1

I'm working on a Django 1.10 & Python 3.6 project, I have deployed it on compute engine successfully with gunicorn.My project is working fine but I have one issue there, I have two models as "Articles" & "TaggedArticle", I have specified all fields from TaggedArticle in admin.py but it doesn't display in Django admin, rather it's displaying all fields in Django admin on my local system. After deployment now I'm using Postgresql instead of SQLite.

Update: Fields are not displaying only in detail view of TaggedArticle in Django Admin

Here are my models:

Article Model:

class Article(models.Model):
    link = models.URLField(max_length=255)
    category = models.CharField(max_length=255, choices=Categories)

TaggedArticle Model:

class TaggedArticle(models.Model):
   user = models.ForeignKey(User, related_name='tagging')
   email = models.EmailField(max_length=255)
   category_fit = models.CharField(choices=choices, max_length=255)
   article = models.ForeignKey(Article, related_name='articles')
   link = models.URLField(max_length=255,)
   relevant_feedback = models.TextField(blank=True)
   category = models.CharField(max_length=255,)
   created_at = models.DateTimeField(default=timezone.now, editable=False)

Here's my admin.py for TaggedArticle:

User =  get_user_model()
admin.site.unregister(User)

class InlineTaggedArticle(admin.TabularInline):
    model = TaggedArticle

class CustomAdmin(UserAdmin):
    date_hierarchy = 'date_joined'
    inlines = [InlineTaggedArticle, ]
    list_display = list(UserAdmin.list_display) + ['totol_tagged_article']

    def totol_tagged_article(self, obj):
        return obj.tagging.all().count()

admin.site.register(User, CustomAdmin)


class TaggedArticleAdmin(admin.ModelAdmin):
    date_hierarchy = 'created_at'
    fields = ['category_fit', 'article', 'link', 'relevant_feedback', 'category', 'user', 'email']
    list_display = ['link', 'user', 'email']
    list_filter = ['user', 'email']
    model = Tagged

admin.site.register(Tagged, TaggedArticleAdmin)

Only category_fit & article fields are displaying in Django admin, why other fields don't display inside Django admin? Even it's displaying other fields like link, user & email as you can see I have added these fields in list_display.

Help me, please! Thanks in advance!

Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
  • Could it be that you have updated your model and did not apply the migration on production? – sinned Oct 20 '17 at 12:21
  • Hi,@sinned! I have applied all migrations! – Abdul Rehman Oct 20 '17 at 12:22
  • 1
    How are you deploying? Are you pulling the code from a git repo in production? If so - are all changes pushed to the correct branch? Make sure that the admin.py in production is *really* what you expect. – Risadinha Oct 20 '17 at 12:36
  • Yup! I have cloned my code from GitHub for the first time only, but now I'm making changes by using nano editor by ssh to my server instance. – Abdul Rehman Oct 20 '17 at 12:38
  • If it works locally and not on production then obviously production doesn't run the same code... So first check what you really have on production (source code etc) AND that you restarted your server processes after deployment. Oh and yes : do NOT edit your code directly on a production server - do your changes locally, _test them_, and once you have a working release deploy it on production. – bruno desthuilliers Oct 20 '17 at 12:40
  • The production runs the same code as locally, I have checked my code line by line, even other fields like user, email, and link from TaggedArticle models are displaying in list view for TaggedArticles in Django admin but not displaying in Detail view, is it possible that the issue may be from DB side as i;m using PostgreSQL on production? – Abdul Rehman Oct 20 '17 at 13:22
  • Did you figure out the issue? – Moulde Mar 07 '18 at 12:41
  • Hi @Moulde, yes I have figured out the issue and that was an issue from DB model as https://stackoverflow.com/questions/46824027/django-import-export-import-duplicate-key-value-violates-error – Abdul Rehman Mar 08 '18 at 08:16
  • Funny, my similar was also with the model, that resulted in the entire form for a model to not render and instead just return an empty string :D, and log it as a warning, not an error.... – Moulde Mar 10 '18 at 14:39

1 Answers1

0

There is an indentation issue, or maybe just typo while writing the question, in your created_at field in TaggedArticle model. Fix this, then apply migrations and check.

Mehroz
  • 71
  • 2