ошибка при копировании приложения django с изменением политики с policyportal на policyportal2020 - PullRequest
0 голосов
/ 18 февраля 2020

policyportal2020.PolicyPortalUser.user_ptr: (fields.E305) Обратное имя запроса для «PolicyPortalUser.user_ptr» конфликтует с обратным именем запроса для «PolicyPortalUser.user_ptr». СОВЕТ: Добавьте или измените аргумент related_name в определении для «PolicyPortalUser.user_ptr» или «PolicyPortalUser.user_ptr».

**, запустив его вместе, эти 2 приложения конфликтуют policyportal и policyportal2020 друг с другом, с которыми я пробовал, Короче говоря, я хочу скопировать вставить приложение внутри django приложения, но с разными именами и одинаковыми функциями. **

#models.py
# Create your models here.
def path_and_rename(prefix, filename):
    ext = filename.split('.')[-1]
    filename = '{}.{}'.format(uuid.uuid4().hex, ext)
    return os.path.join(prefix, filename)

def Resource_Files(instance, filename):
    return path_and_rename('Resource_File', filename)

def Task_Files(instance,filename):
    return path_and_rename('Task Files',filename)

def Offer_Letter(instance,filename):
    return path_and_rename('Policy_Portal/Offer_Letter',filename)

class Notifications(models.Model):
    title = models.TextField(default="Title")
    description = models.TextField(default="Description")
    created = models.DateField(null=True,auto_now=True)
    is_by_mentor = models.BooleanField(default=False)




class Phase(models.Model):
    phase = models.IntegerField(default=0)
    deadline = models.IntegerField(default=15)


    def __str__(self):
        return 'Phase' + ' ' + str(self.phase)

# Policy Portal Model
class PolicyPortalUser(User):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    fname=models.TextField()
    lname=models.TextField()
    mobile_no=models.TextField()

    def __str__(self):
        return self.fname + ' '  + self.lname

# Super Mentor model
class SuperMentor(models.Model):
    pUser = models.ForeignKey(PolicyPortalUser,on_delete=models.CASCADE,null=True,blank=True)

    def __str__(self):
        return self.pUser.fname + ' ' + self.pUser.lname

# Resources Model

class Resources(models.Model):
    text = models.TextField()
    link = models.TextField(null=True)
    image = models.FileField(upload_to=Resource_Files,blank = True, null = True)

    def __str__(self):
        return self.text
#Mentor Model
class Mentor(models.Model):
    pUser = models.ForeignKey(PolicyPortalUser,on_delete=models.CASCADE,null=True,blank=True)

    city = models.CharField(max_length = 40, null = True, blank = True)
    state = models.TextField()


    def __str__(self):
        return self.pUser.fname + ' ' + self.pUser.lname

# Model for co-ordinating teacher
class Teacher(models.Model):
    name = models.CharField(max_length = 50) 
    school = models.CharField(max_length=50) 
    mobile_no = models.IntegerField()
    email = models.CharField(max_length = 30)


class Team(models.Model):

    pUser = models.OneToOneField(PolicyPortalUser,on_delete=models.CASCADE,blank=True,null=True)
    phase = models.ForeignKey(Phase,on_delete=models.DO_NOTHING,blank=True,null=True)
    teacher = models.ForeignKey(Teacher,on_delete=models.DO_NOTHING,blank=True,null=True)

    notifications = models.ManyToManyField(Notifications,blank=True,)
    is_offer_generated = models.BooleanField(default=False)

    id = models.IntegerField(null=True,blank=True)
    team_id = models.CharField(primary_key=True,max_length=30,)
    tname=models.TextField()
    city = models.CharField(max_length = 40, null = True, blank = True)
    state = models.TextField()
    is_member_registered = models.BooleanField(default=False)
    max_members = models.IntegerField(default=4)
    total_score = models.IntegerField(default=0)
    phase_deadline = models.DateTimeField(null=True)
    phase_completed = models.BooleanField(default=False)
    mentor = models.ForeignKey(Mentor,on_delete=models.DO_NOTHING,blank = True, null = True)
    def __str__(self):
        return self.tname



class Tasks(models.Model):
    title = models.TextField()
    description = models.TextField()
    max_score = models.IntegerField(blank=True,null=True)
    phase = models.ForeignKey(Phase , on_delete=models.CASCADE,null=True,blank=True)
    resource = models.ManyToManyField(Resources)
    activity = models.FileField(upload_to=Task_Files,null=True,blank=True)
    marking_scheme = models.TextField(default="No marking scheme provided.")
    is_for_all = models.BooleanField(default=False)
    is_by_mentor = models.BooleanField(default=False)



class Submission(models.Model):
    solution = models.TextField()
    drive_link = models.TextField()
    team = models.ForeignKey(Team,on_delete=models.CASCADE,null=True,blank=True)
    score = models.IntegerField(blank = True,null=True)
    mentor = models.ForeignKey(Mentor,on_delete=models.DO_NOTHING,blank=True,null=True)
    task = models.ForeignKey(Tasks,on_delete=models.DO_NOTHING,blank=True,null=True)
    created = models.DateTimeField(null=True,auto_now=True)
    comment = models.TextField(null=True)

class AssignedTask(models.Model):
    team = models.ForeignKey(Team,on_delete=models.CASCADE,null=True,blank=True)
    task = models.ForeignKey(Tasks,on_delete=models.CASCADE,null=True,blank=True)
    submission = models.ForeignKey(Submission,on_delete=models.DO_NOTHING,blank=True,null=True)
    is_submitted = models.BooleanField(default=False)
    is_evaluated = models.BooleanField(default=False)



class Interns(models.Model):
    fname = models.TextField(null = True)
    lname = models.TextField(null = True)
    org_type = models.CharField(max_length = 20, null = True, blank = True)
    org_name = models.TextField()
    desig = models.TextField()
    email = models.EmailField(null=True)
    mobile_no = models.TextField(null = False)
    team = models.ForeignKey(Team,on_delete=models.CASCADE,null=True,blank=True)
    city = models.TextField(null=True)
    state = models.TextField(null=True)
    offer_letter = models.FileField(upload_to=Offer_Letter,null=True,blank=True)

    is_leader = models.BooleanField(default=False)

    def __str__(self):
        return self.fname + ' ' + self.lname



    def __str__(self):
        return self.team.tname


class NotifiyTeams(models.Model):
    is_read = models.BooleanField(default=False)
    team = models.ForeignKey(Team,null=True,on_delete=models.CASCADE)
    notification = models.ForeignKey(Notifications,null=True,on_delete=models.CASCADE)
[![enter image description here][1]][1]```


  [1]: https://i.stack.imgur.com/eUQSh.png

1 Ответ

0 голосов
/ 18 февраля 2020

Вы можете изменить свой класс PolicyPortalUser следующим образом, и это решит вашу проблему

policyportal2020 app

class PolicyPortalUser(models.Model):
  user = models.OneToOneField(User, on_delete=models.CASCADE, related_name ='PolicyPortal2020User_user')
  ...other fields...

policyportal app

class PolicyPortalUser(models.Model):
  user = models.OneToOneField(User, on_delete=models.CASCADE, related_name ='PolicyPortalUser_user')
  ...other fields...
...