Having a little django problem i'm stuck with... My Model:
class Mymodel(models.Model):
[...]
user = models.ManyToManyField(User)
My attempt to create a new user on it
mymodel = Mymodel.objects.get_or_create(date=date, day=day, time=time) # This one gives a solid Mymodel object i can play with
mymodel.user.add(user) # User is a instance of the Django User System
When trying to execute, it throws 'tuple' object has no attribute 'user'
Did i accidentally turn it into a tuple?
get_or_create
returns a tuple consisting of (object, created). To get just the model, use:
mymodel, _ = Mymodel.objects.get_or_create(date=date, day=day, time=time)
or
mymodel = Mymodel.objects.get_or_create(date=date, day=day, time=time)[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With