I did it in a simple way ;)

I had seperate model class for images and I used inline models in admin
Take a look at code below:

models:
class News(models.Model):
    title = models.CharField("Tytuł", max_length=256)
    text = models.TextField("Treść")
    date_added = models.DateTimeField(editable=False)
    date_edited = models.DateTimeField(editable=False)
    #source = models.ForeignKey("Source", related_name="source_name_set", 
blank=True, null=True)
    created_by = models.ForeignKey(User, default=user_logged_in, 
related_name="news_created_by_set")
   
class Images(models.Model):
    """
    Obrazki - grafika, tytuł, opis.
    """
    image = models.ImageField(upload_to="images/", blank=True, null=True)
    title = models.CharField("Tytuł", max_length=256, blank=True, null=True)
    description = models.CharField("Opis", max_length=256, blank=True, 
null=True)
    news = models.ForeignKey(News)
    
    class Meta:
        verbose_name = "Zdjęcie"
        verbose_name_plural = "Zdjęcia"
        
    def __unicode__(self):
        return unicode(self.description)

ADMIN

class ImagesInline(admin.TabularInline):
    model = Images
    extra = 1

class NewsAdmin(admin.ModelAdmin):
    date_hierarchy = 'date_added'
    list_display = ('date_added',  'title', 'created_by')
    list_display_links = ('date_added', 'title', 'created_by', )
    
    readonly_fields = ('date_added', 'date_edited')
    fieldsets = [
        (None,               {'fields': ['title', 'text']}),
        ('Additional info', {'fields': ['created_by', 'date_added']}),
    ]
    
    inlines = [SourceInline, CategoryInline, ImagesInline]
    
    def __unicode__(self):
        return self.title

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_esm3Masjv0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to