Skip to content

Instantly share code, notes, and snippets.

@bluethon
Last active September 11, 2016 07:00
Show Gist options
  • Save bluethon/799c61c573104f2827cb35ee7707b2d8 to your computer and use it in GitHub Desktop.
Save bluethon/799c61c573104f2827cb35ee7707b2d8 to your computer and use it in GitHub Desktop.
group attribute demo
class some():
groups = models.ManyToManyField(
Group,
verbose_name='组',
blank=True,
# help_text='The groups this user belongs to. A user will get all '
# 'permissions granted to each of their groups.',
related_name="user_set",
related_query_name="user",
)
def func():
new_group, created = Group.objects.get_or_create(name='campaign')
if new_group:
user.groups.add(new_group)
else:
user.groups.add(created)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment