Login

Tag "user-foreign-key"

Snippet List

User manager

If you have a model with foreign key to User, you can use this manager to show (i.e. in admin interface) only objects, that are related to currently logged-in user. Superuser sees all objects, not only his. Requires: [ThreadlocalsMiddleware](http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser)

  • filter
  • foreignkey
  • user
  • manager
  • queryset
  • owner
  • users
  • user-foreign-key
Read More

another UserForeignKey

This is another foreign key to User model. User is automatically associated before save. Requires: [ThreadlocalsMiddleware](http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser) Inspired by: [snippet 509](http://www.djangosnippets.org/snippets/509/)

  • foreignkey
  • model
  • user
  • field
  • users
  • user-foreign-key
Read More

Active User Sorted ModelAdmin

Since r7806, the `User` field is unsorted which makes it harder to find specific users in the list if there is more than a few. This snippet is an `django.contrib.admin.ModelAdmin` subclass which searches through all of the fields on a form and automatically sorts fields which have a relation with `User`. It also filters on having `active=True`. Just import the `SortedActiveUserModelAdmin` class in your `admin.py` and subclass your `ModelAdmin` classes from it instead of `admin.ModelAdmin`.

  • sorting
  • modeladmin
  • user-foreign-key
Read More

3 snippets posted so far.