Skip to content

Commit

Permalink
Merge pull request #90 from jackton1/update-the-short-description
Browse files Browse the repository at this point in the history
Update admin.py
  • Loading branch information
jackton1 authored Jun 4, 2020
2 parents afc1b8c + 14e40e2 commit 3c752fe
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Binary file modified Duplicate-action.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion model_clone/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def make_clone(self, request, queryset):
_("Successfully created: {} new duplicates".format(len(clone_obj_ids))),
)

make_clone.short_description = "Duplicate selected objects"
make_clone.short_description = "Duplicate selected %(verbose_name_plural)s"

def _get_base_actions(self):
"""Return the list of actions, prior to any request-based filtering."""
Expand Down
8 changes: 4 additions & 4 deletions model_clone/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def create_copy_of_instance(instance, exclude=(), save_new=True, attrs=None):

def clean_value(value, suffix):
# type: (str, str) -> str
return re.sub(r"{}\s[\d]$".format(suffix), "", value, flags=re.I)
return re.sub(r"\s{}\s[\d]$".format(suffix), "", value, flags=re.I)


@contextlib.contextmanager
Expand Down Expand Up @@ -117,7 +117,7 @@ def get_value(value, suffix, max_length, index):

if total_length > max_length:
# Truncate the value to max_length - suffix length.
value = value[: max_length - len(duplicate_suffix)]
value = value[:max_length - len(duplicate_suffix)]

return "{}{}".format(value, duplicate_suffix)

Expand All @@ -134,13 +134,13 @@ def generate_value(value, suffix, max_length, max_attempts):


def get_unique_value(obj, fname, value, suffix, max_length, max_attempts):
qs = obj.__class__._default_manager.exclude(pk=obj.pk)
qs = obj.__class__._default_manager.all()
it = generate_value(value, suffix, max_length, max_attempts)

new = six.next(it)
kwargs = {fname: new}

while not new or qs.filter(**kwargs):
while qs.filter(**kwargs).exists():
new = six.next(it)
kwargs[fname] = new

Expand Down
3 changes: 1 addition & 2 deletions sample/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib import admin

# Register your models here.

from model_clone import CloneModelAdmin
from sample.models import Book, Author

Expand All @@ -13,4 +12,4 @@ class BookAdmin(CloneModelAdmin):

@admin.register(Author)
class AuthorAdmin(CloneModelAdmin):
pass
list_display = ['first_name', 'last_name', 'sex', 'age']
4 changes: 4 additions & 0 deletions sample/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Author(CloneModel):
def __str__(self):
return _("{} {}".format(self.first_name, self.last_name))

@property
def full_name(self):
return "{} {}".format(self.first_name, self.last_name)


class Book(CloneModel):
name = models.CharField(max_length=2000)
Expand Down

0 comments on commit 3c752fe

Please sign in to comment.