Is there a way to associate one user with multiple things?


#1

I want to allow one user to own(create) multiple things. I’ve tried this in settings.py:


slug = models.SlugField (unique = False)
user = models.OneToOneField(User, blank=True, null=True)

but that broke the app.

Should I remove OneToOneField?


#2

Hi @balthazar,

First, I think you mean models.py, not settings?

Second, is the change you made changing SlugField to False? You do want your objects to have unique slugs, so that should be True.

I recommend reading up on modelFields, check out the Django documentation, particularly on ForeignKeys: https://docs.djangoproject.com/en/2.0/ref/models/fields/#foreignkey, which should allow for multiple things with one user.


#3

Yes models.py, sorry.
Will try that.
Thanks!


#4

It worked! Thanks for the solution.
Replaced OneToOneField by ForeignKey .