Reverse accessor clashes in Django
<p>Error :
1) user.Login.password: (fields.E304) Reverse accessor for 'Login.password' clashes with reverse accessor for 'Login.username'.
2) user.Login.username: (fields.E304) Reverse accessor for 'Login.username' clashes with reverse accessor for 'Login.password'.</p>

<p>models.py</p>

<pre><code>from django.db import models
from django.core.urlresolvers import reverse

class User(models.Model):
     first_name = models.CharField(max_length=50)
     last_name = models.CharField(max_length=50)
     username = models.CharField(max_length=100)
     password = models.CharField(max_length=50)
     confirm_password = models.CharField(max_length=50)
     email = models.EmailField(max_length=100)
     position = models.CharField(max_length=50)

     def get_absolute_url(self):
           return reverse('user:register', kwargs={'pk': self.pk})

class Login(models.Model):
     username = models.ForeignKey(User, on_delete=models.CASCADE)
     password = models.ForeignKey(User, on_delete=models.CASCADE)

     def __str__(self):
          login = {'username': self.username, 'password': self.password}
          return login
</code></pre>

<p>You can solve the issue by using <code>related_name</code> attribute:</p>

<pre><code>class Login(models.Model):
     username = models.ForeignKey(User, on_delete=models.CASCADE, related_name="username_users")
     password = models.ForeignKey(User, on_delete=models.CASCADE, related_name="password_users")
</code></pre>

<p>But I am not getting the reason for you having both password and username having fk relation with User!!!</p>

python django