I get a area clash during my models:
class Visit(models.Model): user = models.ForeignKey(User) visitor = models.ForeignKey(User) Error: One or more models did not validate: profiles.visit: Accessor for field 'user' clashes with related field 'User.visit_set'. Add a related_name argument to the definition for 'user'. profiles.visit: Accessor for field 'visitor' clashes with related field 'User.visit_set'. Add a related_name argument to the definition for 'visitor'.
what will be a sensible 'related_field' to experience customer area? This model essentially signifies the visits that occur to some particular user's profile.
Should also I replace the ForeignKey's having a ManyToManyField? The logic is a little confusing.
Edit: This appears to repair it, however i am unsure if it is things i want. :)
class Visit(models.Model): user = models.ForeignKey(User) visitor = models.ForeignKey(User, related_name='visitors')
If you have a
ForeignKey, it produces a house named using the model title plus
_set towards the recommended model. The issue here's that both foreign secrets are thinking about creating a house on
visit_set. The answer would be to add related names which are different for every foreign key.
Usually, I personally use plurals for related names. In the event such as these, I add an "as" clause towards the related title:
class Visit(models.Model): user = models.ForeignKey(User, related_name="visitsAsUser") visitor = models.ForeignKey(User, related_name="visitsAsVisitor")
You wouldn't want a
ManyToManyField unless of course you could have zero or even more site visitors per
Visit, or customers per
If your visit is really a strong concept inside your application, it will make sense to be how you defined: visit includes a 'user user' along with a 'user visitor'.
If, however, a visit is simply a means by which customers relate among themselves, then possibly you ought to have a
ManyToMany relation between customers. For your purpose you need to most likely use ManyToManyField.shaped inside a Account (that you extend the data that accompany
Regardless, concerning the related_title, you can disable the backwards relation should you will not be being able to access the visits in the user, or make use of a sensible title for example
visitor, which may allow seeing who visited a person by calling
user.visits_to_self and who the consumer visited by