These are chat archives for django/django

Oct 2018
Oct 16 2018 07:35

I’m having a little troubles . I’m trying to show an object from my database to my html webpage

I have it set up to render(request, homepage/index.html, {“quote”: quote}) . I then use the for loop in my index template but it will not show up, but I can use {{quote}} and get the object in the database. Any help?

Tanveer Ahmed
Oct 16 2018 13:26
Screenshot from 2018-10-16 18-14-04.png
DETAIL: Key (gcategory_id)=(1) is duplicated.
I am getting this error when I did makemigrations and migrate I am using Postgresql Please help me :(
Oct 16 2018 15:27
@tanveerobjects_twitter what’s the code you have? I can try to look at it and see .
Corey Vincent
Oct 16 2018 18:06

Can anyone help me with Django admin forms?
I'm trying to automatically set a field when it's saved, but it doesn't seem to work.
My understanding was to do the following:

class BlogPost(models.Model):
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    posted_date = models.DateField(
    title = models.CharField(max_length=200)
    text = models.TextField(max_length=1000)
# in
class BlogPostAdmin(admin.ModelAdmin):
    model = BlogPost
    def formfield_for_choice_foreignkey(self, db_field, request, **kwargs):
        if == 'author':
            kwargs['queryset'] = User.objects.filter(username=request.user.username)
        return super(BlogPostAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)

Preferably I would like the field to just be hidden when editing or creating a new BlogPost.

Oct 16 2018 19:38
@CoreyVincent I don't understand why you don't just set the field in your model's save function and include it in ModelAdmin.exclude. Which field are you trying to set?
Oct 16 2018 19:46
@damionsilver98 not sure I entirely follow - you can display quote but not in a loop? Is quote iterable?
@tanveerobjects_twitter the table you are trying to create a unique index on already has rows in it which are not unique. If the data is not important then empty the table...