A
A
Andrew2011-11-04 23:11:56
Django
Andrew, 2011-11-04 23:11:56

Models in django?

Good afternoon!
Learning models in django and trying to figure out how best to organize them?
For example, I have a User model and a UserBalance model.
How best to relate them to each other? Add the Balance field to the User, and the user field to the Balance? Or in some other way?
A friend said that django will pull out the custom balance object by itself if you access the balance property, but how easy is that to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2011-11-05
@seneast

Model:

class Balance(models.Model):
    user = models.OneToOneField(User, related_name='balance')
    value = models.DecimalField()

Balance access:
user_balance = user.balance.value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question