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. Username form field by sma 3 years, 6 months ago
  2. Update Related Object Fields by johnboxall 3 years, 5 months ago
  3. User manager by diverman 2 years, 10 months ago
  4. Email on new comments by nikolaj 4 years, 9 months ago
  5. Duplicate related objects of model instance by johnboxall 3 years, 4 months ago

Comments

(Forgotten your password?)