OwnerField

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.contrib.auth.models import User

class OwnerField(User):
    def get_internal_type(self):
        return User.__name__
    def pre_save(self, model_instance, add):
        if model_instance.id is None:
            return get_current_user()
        else:
            return getattr(model_instance, self.attname)

More like this

  1. User manager by diverman 3 years, 10 months ago
  2. another UserForeignKey by diverman 3 years, 10 months ago
  3. PreSaveMiddleware by pterk 5 years, 6 months ago
  4. keeping Model and Field History (everywhere) by buriy 4 years, 8 months ago
  5. ImageField with per user folder by pigletto 5 years, 4 months ago

Comments

(Forgotten your password?)