django_builder icon indicating copy to clipboard operation
django_builder copied to clipboard

Import models.py doesn't handle Abstract models

Open mmcardle opened this issue 9 years ago • 2 comments

The following import of a models.py file generates a single model called Amodel with all the fields of Model1 and Model2

class AModel(models.Model):
    name = models.CharField(max_length=255)

    class Meta:
        abstract = True


class Model1(AModel):

    # Fields
    slug = extension_fields.AutoSlugField(populate_from='name', blank=True)
    created = models.DateTimeField(auto_now_add=True, editable=False)
    last_updated = models.DateTimeField(auto_now=True, editable=False)


    class Meta:
        ordering = ('-created',)

    def __unicode__(self):
        return u'%s' % self.slug

    def get_absolute_url(self):
        return reverse('app_name_model1_detail', args=(self.slug,))


    def get_update_url(self):
        return reverse('app_name_model1_update', args=(self.slug,))


class Model2(AModel):

    # Fields
    slug = extension_fields.AutoSlugField(populate_from='name', blank=True)
    created = models.DateTimeField(auto_now_add=True, editable=False)
    last_updated = models.DateTimeField(auto_now=True, editable=False)


    class Meta:
        ordering = ('-created',)

    def __unicode__(self):
        return u'%s' % self.slug

    def get_absolute_url(self):
        return reverse('app_name_model2_detail', args=(self.slug,))


    def get_update_url(self):
        return reverse('app_name_model2_update', args=(self.slug,))

mmcardle avatar Sep 21 '16 07:09 mmcardle

Another, different? issue, is that when importing a models.py, say the one you just created with Django Builder, Relationship fields do not seem to be imported at all.

RichardBH avatar Oct 13 '18 01:10 RichardBH

I will take a look, Thanks!

mmcardle avatar Oct 13 '18 09:10 mmcardle