Skip to content

Instantly share code, notes, and snippets.

@vmwsree
Last active June 11, 2018 13:15
Show Gist options
  • Save vmwsree/63dde64d3384a1d64338aa89a67faddb to your computer and use it in GitHub Desktop.
Save vmwsree/63dde64d3384a1d64338aa89a67faddb to your computer and use it in GitHub Desktop.
class HeroImage(ImageMixin):
    image = VersatileImageField(upload_to=upload_to, ppoi_field='image_poi',
                                verbose_name="image")
    image_poi = PPOIField(verbose_name="image's Point of Interest")  # point of interest
    caption = models.CharField(max_length=250, blank=True)
    centre = models.ForeignKey('website.CentreList')
    sort_order = models.PositiveIntegerField(default=0)

    created = models.DateTimeField(auto_now_add=True, editable=False)
    modified = models.DateTimeField(auto_now=True, editable=False)

    class Meta:
        ordering = ('sort_order', )

    def __str__(self):
        return "{}".format(self.caption)
        

admin.py


class HeroImageInline(admin.TabularInline):
    fields = ('caption', 'image', 'sort_order', )
    model = models.HeroImage
    extra = 0
    
    
@admin.register(CentreList)
class CentreListAdmin(admin.ModelAdmin):
    fields = ('title', 'city', 'slug', 'description', 'overview', 'address', 'image', 'featured_image', 'hot_desk_price',
              'dedicated_desk_price', 'is_visible', 'is_comming_soon', 'classic_widget_lead','meta_title','meta_keywords',
              'meta_description', 'tour_manager_name', 'tour_manager_image', 'tour_request_sent_to', 'invoice_receipt_sent_to', 'place_id', 'hub_staff_user', 'account_id')
    list_display = ['title', 'city', 'is_visible', 'is_comming_soon']
    list_filter = ['is_visible', 'is_comming_soon']
    filter_horizontal = ('coworkers', )
    prepopulated_fields = {'slug': ['title']}
    inlines = [HeroImageInline, PrivateSpacePlanInline, AmenitiesInline]


this is a base model, abstract model


class ImageMixin(models.Model):
    """
    An abstract base class model that provides a VersatileImageField Image with POI
    """

    image = VersatileImageField(upload_to=upload_to, blank=True, null=True, ppoi_field='image_poi',
                                verbose_name="image")
    image_poi = PPOIField(verbose_name="image's Point of Interest")  # point of interest

    class Meta:
        abstract = True
       
       
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment