1👍
✅
The constructor will work if you do:
class Stuff(models.Model):
id = fields.UUIDField(primary_key=True)
name = models.CharField(max_length=128)
enabled = models.BooleanField(default=False)
log_user = None
def __init__(self, log_user=None, *args, **kwargs):
super(Stuff, self).__init__(*args, **kwargs)
self.log_user = log_user
1👍
You need ForeignKey here.
class Stuff(models.Model):
id = fields.UUIDField(primary_key=True)
name = models.CharField(max_length=128)
enabled = models.BooleanField(default=False)
log_user = models.ForeignKey('auth.User', blank=True, null=True)
- [Answered ]-Django return different class-based view according to whether an object has been created
- [Answered ]-Django: manage.py works fine but django-admin fails
- [Answered ]-In SQLAlchemy, how to input a list and get eligible items in the table?
- [Answered ]-Generate PDF from ODT
- [Answered ]-Django FileField in model maximum recursion depth exceeded while calling a Python object
0👍
Django recommend to use as a Foreign key Concept:
class Stuff(models.Model):
id = fields.UUIDField(primary_key=True)
name = models.CharField(max_length=128)
enabled = models.BooleanField(default=False)
log_user = models.ForeignKey('auth.User', blank=True, null=True)
while saving your Data you can add log_user object:
Stuff = Stuff()
stuff.log_user = user
stuff.save()
- [Answered ]-Change order ModelChoiceField
- [Answered ]-Django is doubling my get parameters when I make a redirect, but only on our server
Source:stackexchange.com