Daniel Mendoza
Daniel Mendoza

Reputation: 37

How to save two different users in a django model?

My case is related to a purchase, the customer who buys something and the seller who sold it.

Models.py

from django.contrib.auth.models import User

class buy(models.Model):
    customer = models.ForeignKey(User)
    seller   = models.ForeignKey(User)

I am aware that the above code is wrong, I write it that way so the question is understood.

I take the django.contrib authentication system, to avoid having to make another authentication system for clients and one for sellers, I want django code reuse.

A solution had thought of creating another data model to sellers or customers, but in my view and in the login I'm using django.contrib, then I would still use this system authentication would like to know if there is any way or if I ultimately that create another authentication system?

Upvotes: 1

Views: 219

Answers (1)

qasimalbaqali
qasimalbaqali

Reputation: 2131

I'm just guessing, if you have a Product model that has a user field in which case he's the actual seller, why don't you use seller = models.ForeignKey(Product, to_field='user')

Upvotes: 1

Related Questions