mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-05-23 22:55:48 +00:00
special case for AVATAR_MAX_AVATARS_PER_USER == 1: try to work always on the same db row, by re-using the id.
This commit is contained in:
parent
cbb8421720
commit
afde1c6268
1 changed files with 4 additions and 1 deletions
|
|
@ -33,7 +33,10 @@ class Avatar(models.Model):
|
|||
return _(u'Avatar for %s') % self.user
|
||||
|
||||
def save(self, force_insert=False, force_update=False):
|
||||
if self.primary and AVATAR_MAX_AVATARS_PER_USER > 1:
|
||||
if AVATAR_MAX_AVATARS_PER_USER == 1:
|
||||
first = Avatar.objects.filter(user=self.user).only('id')[0]
|
||||
self.id = first.id
|
||||
elif self.primary and AVATAR_MAX_AVATARS_PER_USER > 1:
|
||||
avatars = Avatar.objects.filter(user=self.user, primary=True)\
|
||||
.exclude(id=self.id)
|
||||
avatars.update(primary=False)
|
||||
|
|
|
|||
Loading…
Reference in a new issue