neon-jungle / wagtail-videos

Videos for Wagtail CMS, including transcoding
BSD 3-Clause "New" or "Revised" License
65 stars 57 forks source link

Unable to add new field to any model #38

Closed ManojDatt closed 4 years ago

ManojDatt commented 4 years ago

I was trying to use this package and here my requirement was to add new category field to video. But i don't find any way to add new field to model. Even i try by inheriting AbstractVideo model to new model but it created a separate model that has different UI.

from django.db import models
from wagtailvideos.models import AbstractVideo
class CustomVideo(AbstractVideo):
    category = models.ForeignKey("category.Category",blank=False,null=True, on_delete=models.CASCADE)
    slug = models.SlugField(null=True)
    access = models.CharField(verbose_name=('Access Type'), default="PUBLIC", choices=ACCESS, max_length=50, blank=True, null=True)

    def save(self, args, *kwargs):
        self.slug = slugify(self.title)
        super(AbstractVideo, self).save(**kwargs)

    admin_form_fields = (
        'title',
        'file',
        'collection',
        'thumbnail',
        'tags',
        'category', 
        'slug', 
        'access', )

Is there any one who can help me in this ?

seb-b commented 4 years ago

There isn't a way at the moment to customise the Video model.

I'm open to a merge request that would add functionality similar to images where you can specify a custom model via a setting.

You could also possibly use snippets or modeladmin in a reverse way to add extra properties to a video:


class VideoProperties(models.Model):
   video = models.OneToOneField('wagtailvideos.Video', related_name='properties', on_delete=models.CASCADE)
   category = models.ForeignKey("category.Category",blank=False,null=True, on_delete=models.CASCADE)
   slug = models.SlugField(null=True)
   access = models.CharField(verbose_name=('Access Type'), default="PUBLIC", choices=ACCESS, max_length=50, blank=True, null=True)

Then to access the properties in a template:

{{ video.properties.slug }}
ManojDatt commented 4 years ago

Hi Thanks for your information. But I have made changes in package and make new repository on my GitHub account.