[Answer]-Django error on importing class from model

1👍

✅

You may be having circular imports. You are importing the Region class in the models.py file containing your Character class while importing the Character class in the models.py file containing the Region class.

Try replacing your Character class with this

from django.db import models

class Character(models.Model):
""" User characters that hold the personal game stats """
created = models.DateTimeField(auto_now_add=True)
alive = models.BooleanField(default=True)
name = models.CharField(max_length=63, unique=True)
xp = models.IntegerField(default=0)
region = models.ForeignKey('elements.Region')
alliance = models.ForeignKey('Alliance', null=True)
credit = models.IntegerField(default=0)
bullets = models.IntegerField(default=0)
hitpoints = models.IntegerField()
accuracy = models.FloatField(default=0)

def __unicode__(self):
    return self.name

Leave a comment