예제 #1
0
class Track(models.Model):
    album = models.ForeignKey(Album, related_name='track_set')
    title = models.CharField(_('Title'), max_length=128, default="untitled")
    video = EmbedVideoField(_('Video Link'),
                            null=True,
                            blank=True,
                            help_text="Link to youtube or vimeo")
    audio = AudioField(_("Audio file"),
                       upload_to=get_audio_upload_path,
                       ext_whitelist=('.mp3', '.ogg'),
                       help_text="Currently supports mp3 and ogg",
                       null=True,
                       blank=True)
    order = models.PositiveSmallIntegerField(verbose_name=_("order"))

    class Meta:
        ordering = ['order']

    def __unicode__(self):
        return '%s' % self.id

    def set_upload_to_info(self, username, track_type, album_title=None):
        """
            username = username of who saving the model
            track_type = albums/covers/interviews
            album_title = if album whats its title
        """
        self.upload_to_info = (username, track_type, album_title)
예제 #2
0
class Song(models.Model):
    pic = models.ImageField(upload_to="images/albumart/")
    songName = models.CharField(max_length = 30)
    artistName = models.CharField(max_length = 30,null=True)
    # audio_track = models.FileField(upload_to="songs/")
    audio_track = AudioField(upload_to='songs/', blank=True,
                        ext_whitelist=(".mp3", ".wav", ".ogg"),
                        help_text=("Allowed type - .mp3, .wav, .ogg"))

    lyrics = models.TextField(default='',blank = True)

    def __unicode__(self):
        return self.songName

    @classmethod
    def get_song_by_id(cls,song_id):
        songs= Song.objects.get(id=song_id)
        return songs

    @classmethod
    def search_by_artist(cls, search_input):
        songs = cls.objects.filter(artistName__name__icontains=search_input)
        return songs 

    # @classmethod 
    # def audio_file_player(self):
    
    
    #    if self.audio_track:
    #         file_url = settings.MEDIA_URL + str(self.audio_track)
    #         player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (file_url)
    #         return player_string
    #         audio_file_player.allow_tags = True
    #         audio_file_player.short_description = ('Audio file player')  
예제 #3
0
class AudioFile(models.Model):
    name = models.CharField(max_length=50)
    tags = models.CharField(max_length=200)
    parse = models.CharField(max_length=500)
    upload_at = models.DateTimeField(auto_now_add=True)
    audio_file = AudioField(upload_to='audio',
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"))

    def __str__(self):
        return '[%s] %s' % (self.id, self.name)

    class Meta:
        default_permissions = ('add', 'change', 'delete')
        verbose_name = 'audio file'
        verbose_name_plural = 'audio files'

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (
                file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')
예제 #4
0
class Podcast(models.Model):
    title = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(max_length=100, unique=True)
    creator = models.ForeignKey(Blogger, null=True, on_delete=models.CASCADE)
    description = models.TextField(max_length=1000)
    itunes_explicit = models.BooleanField(default=True)
    pubdate = models.DateField(db_index=True, auto_now_add=True)
    pic = models.ForeignKey(Pic,
                            blank=True,
                            null=True,
                            on_delete=models.SET_NULL)
    audio_file = AudioField(ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"))
    promos = models.ManyToManyField(Promo, blank=True)

    class Meta:
        db_table = "blog_podcast"

    def __str__(self):
        return self.title

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (
                file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')
예제 #5
0
class AudioFile(models.Model):
    name = models.CharField(max_length=150,
                            blank=False,
                            help_text=('audio file label'))
    audio_file = AudioField(
        upload_to='music',
        blank=True,
        ext_whitelist=('.mp3', '.wav', '.ogg'),
    )
    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               on_delete=models.CASCADE,
                               related_name='user')

    def audio_file_player(self):
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<ul class="playlist"><li style="width:250px;">\
            <a href="%s">%s</a></li></ul>' % (
                file_url, os.path.basename(self.audio_file.name))
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')

    def __str__(self):
        return self.name

    class Meta:
        permissions = (('can_view_audiofile', ('Audio File', )), )
예제 #6
0
class UploadMusic(models.Model):
  user = models.OneToOneField(AUTH_USER_MODEL, on_delete=models.CASCADE)
  title = models.CharField(max_length=200)
  composer = models.CharField(max_length=200, default='')
  description = models.TextField(blank=True)
  album_cover = models.ImageField(upload_to='album_cover/%Y/%m/%d/')
  genre = models.CharField(max_length=30, default='select a genre',choices=GENRE_CHOICES)
  audio_file = AudioField(upload_to='media/songs/',blank=False,null=False,default='',
                        ext_whitelist=(".mp3", ".wav", ".ogg"),
                        help_text=("Allowed type - .mp3, .wav, .ogg"))

  created_date = models.DateTimeField(default=datetime.now, blank=True)
  allow_listening = models.BooleanField(default=True)
  def get_absolute_url(self):
      return reverse("song_update", kwargs={'pk': self.pk})

  def __str__(self):
    return self.user.username


  def audio_file_player(self):
    """audio player tag for admin"""
    if self.audio_file:
      file_url = settings.MEDIA_URL + str(self.audio_file)
      player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (file_url)
      return player_string


  audio_file_player.allow_tags = True
  audio_file_player.short_description = ('Audio file player')
예제 #7
0
class Audio(models.Model):

    title = models.CharField(_("Titile"), max_length=100)
    audio_file = AudioField(upload_to=files_directory_path,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"))
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<ul class="playlist"><li style="width:250px;">\
            <a href="%s">%s</a></li></ul>' % (
                file_url, os.path.basename(self.audio_file.name))
            return mark_safe(player_string)

    audio_file_player.allow_tags = True
    audio_file_player.short_description = _('Audio file player')

    class Meta:
        ordering = ['-created_at', '-updated_at']

    def __str__(self):
        return self.title
예제 #8
0
class MyAudioFile(models.Model):

    audio_file = AudioField(upload_to='api', blank=True,\
                        ext_whitelist=(".mp3", ".wav", ".ogg"),\
                        help_text=("Allowed type - .mp3, .wav, .ogg"))

    ivector = models.TextField(null=True)
예제 #9
0
class AudioFile(models.Model):
    """
    This Model describe the Audio used on the platform,
    this allow to upload audio file and configure
    alternate Text2Speech System
    """
    name = models.CharField(max_length=150,
                            blank=False,
                            verbose_name=_('audio name'),
                            help_text=_('audio file label'))
    audio_file = AudioField(upload_to='upload/audiofiles',
                            blank=True,
                            ext_whitelist=('.mp3', '.wav', '.ogg'),
                            verbose_name=_('audio file'))
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             verbose_name=_('user'),
                             help_text=_('select user'))
    tag = models.CharField(
        max_length=50,
        blank=True,
        null=True,
        verbose_name=_('tag'),
        help_text=_('tag used to categorize the audio files'))
    created_date = models.DateTimeField(auto_now_add=True)
    updated_date = models.DateTimeField(auto_now=True)

    class Meta:
        permissions = (('can_view_audiofile', _('can see Audio Files')), )
        db_table = 'audio_file'
        verbose_name = _('audio file')
        verbose_name_plural = _('audio files')

    def __str__(self):
        return '[%s] %s' % (self.id, self.name)

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        # Call the "real" save() method
        super(AudioFile, self).save(force_insert, force_update, using,
                                    update_fields)

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % \
                (file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = _('audio file player')
예제 #10
0
class Post(models.Model):
    """
        Blog Posts
    """

    STATUS_CHOICES = (
        ('draft', 'Draft'),
        ('published', 'Published'),
    )
    title = models.CharField(max_length=250)
    cover = models.ImageField(upload_to="cover")
    #icon=models.ImageField(upload_to="icon", null=True, blank=True)
    body = models.TextField()
    slug = models.SlugField(max_length=250, unique_for_date="publish")
    author = models.ForeignKey(User, related_name="blog_posts")
    publish = models.DateTimeField(default=timezone.now)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    document = models.FileField(upload_to="document")
    audio_file = AudioField(upload_to='audios',
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"))
    status = models.CharField(max_length=10,
                              choices=STATUS_CHOICES,
                              default='draft')

    #tags = TaggableManager()

    objects = models.Manager()  # The default manager.
    published = PublishedManager()  # Our custom manager.

    class Meta:
        ordering = ('-publish', )

    def __str__(self):
        return self.title

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            #player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (file_url)
            return file_url

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')

    def get_absolute_url(self):
        return reverse('post_detail',
                       args=[
                           self.publish.year,
                           self.publish.strftime('%m'),
                           self.publish.strftime('%d'), self.slug
                       ])
예제 #11
0
class Greeting(models.Model):
    when = models.DateTimeField('date created', auto_now_add=True)
    # Add the audio field to your model
    audio_file = AudioField(upload_to='./',
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"))

    # Add this method to your model
    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (
                file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')
예제 #12
0
class AudioFile(Model):
    """
    This Model describe the Audio used on the platform,
    this allow to upload audio file and configure
    alternate Text2Speech System
    """
    name = models.CharField(max_length=150,
                            blank=False,
                            verbose_name=_("audio name"),
                            help_text=_('audio file label'))
    audio_file = AudioField(upload_to='upload/audiofiles',
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            verbose_name=_("audio file"))
    user = models.ForeignKey(User,
                             verbose_name=_('user'),
                             help_text=_("select user"))
    created_date = models.DateTimeField(auto_now_add=True)
    updated_date = models.DateTimeField(auto_now=True)

    class Meta:
        permissions = (("view_audiofile", _('can see Audio Files')), )
        db_table = u'audio_file'
        verbose_name = _("audio file")
        verbose_name_plural = _("audio files")

    def __unicode__(self):
        return '[%s] %s' % (self.id, self.name)

    def save(self):
        super(AudioFile, self).save()  # Call the "real" save() method

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<ul class="playlist"><li style="width:250px;">\
            <a href="%s">%s</a></li></ul>' % (file_url,
                                              os.path.basename(file_url))
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = _('audio file player')
예제 #13
0
파일: models.py 프로젝트: back1992/firefly
class Chapter(models.Model):
    no = models.IntegerField(db_index=True)
    title = models.CharField(max_length=100, null=True, verbose_name=u"章节标题")
    npid = models.CharField(max_length=30, null=True, default='npid')
    book = models.ForeignKey(Book,
                             on_delete=models.CASCADE,
                             verbose_name=u"所属书籍")
    content = RichTextField(_("Content"))
    audio_file = AudioField(upload_to="audiofiles",
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"),
                            verbose_name=u"音频文件")

    # Add this method to your model
    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<ul class="playlist"><li style="width:250px;">\
            <a href="%s">%s</a></li></ul>' % (
                file_url, os.path.basename(self.audio_file.name))
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = (u'音频文件')

    # def custom_action(self):
    #     return format_html(
    #         ' <a href="/admin/backend/chapter/{}/change/" class ="viewsitelink" target="_blank" >edit</a>',
    #         self.id
    #     )

    # custom_action.short_description = u"操作"

    def __str__(self):
        # return self.book.title + str(self.no)
        return "%s: 第%s章节" % (self.book.title, self.no)

    class Meta:
        verbose_name = u'章节管理'
        verbose_name_plural = u'章节管理'
class Recording(models.Model):
	transcript = HTMLField(blank=True)
	transcript_document = models.FileField(upload_to='transcripts/', null=True, blank
		=True)

	audio_file = AudioField(upload_to='recordings', blank=True,
                        ext_whitelist=(".mp3", ".wav", ".ogg"),
                        help_text=("Allowed type - .mp3, .wav, .ogg")) 
	names = models.ForeignKey(Name, on_delete=models.CASCADE)
	slug = models.SlugField( \
		unique=True, \
		blank=True, \
		null=True,
	)

	@property
	def file_url(self) :
		return settings.MEDIA_URL + str(self.audio_file.name)

	@property
	def extension(self):
		return str(self.audio_file).split('.')[-1].upper()

	@property
	def json_friendly_transcript(self):
		return simplejson.JSONEncoderForHTML().encode(self.transcript)


	def audio_file_player(self):
		 """audio player tag for admin"""
		 if self.audio_file:
			  file_url = settings.MEDIA_URL + str(self.audio_file)
			  player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (self.file_url)
			  return player_string

	audio_file_player.allow_tags = True
	audio_file_player.short_description = ('Audio file player')
예제 #15
0
class My_Test(models.Model):
    title = models.CharField(max_length=32)
    test_id = models.AutoField(primary_key=True)
    test_owner = models.CharField(max_length=32)
    # file = models.f

    # Create your models here.
    # Add the audio field to your model
    audio_file = AudioField(upload_to='your/upload/dir',
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"))

    # Add this method to your model
    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (
                file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')
예제 #16
0
class Song(models.Model):
    Artist = models.CharField(max_length=250)
    SongTitle = models.CharField(max_length=250)
    # Add the audio field to your model
    audio = AudioField(upload_to='media/upload/',
                       blank=True,
                       ext_whitelist=(".mp3", ".wav", ".ogg"),
                       help_text=("Allowed type - .mp3, .wav, .ogg"))
    date_added = models.DateField(auto_now_add=True)

    # Add this method to your model
    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (
                file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')

    def __str__(self):
        return self.Artist + "sang" + SongTitle
예제 #17
0
from django.db import models

# Create your models here.

from django.conf import settings
from audiofield.fields import AudioField
import os.path

# Add the audio field to your model
audio_file = AudioField(upload_to='your/upload/dir',
                        blank=True,
                        ext_whitelist=(".mp3", ".wav", ".ogg"),
                        help_text=("Allowed type - .mp3, .wav, .ogg"))


# Add this method to your model
def audio_file_player(self):
    """audio player tag for admin"""
    if self.audio_file:
        file_url = settings.MEDIA_URL + str(self.audio_file)
        player_string = '<ul class="playlist"><li style="width:250px;">\
        <a href="%s">%s</a></li></ul>' % (
            file_url, os.path.basename(self.audio_file.name))
        return player_string


audio_file_player.allow_tags = True
audio_file_player.short_description = ('Audio file player')
예제 #18
0
class Document(models.Model):
    """A document being annotated"""
    owner = models.ForeignKey(User, blank=True, null=True)
    created = models.DateTimeField(auto_now_add=True, db_index=True)
    title = models.CharField(max_length=64,
                             db_index=True,
                             null=True,
                             blank=True)

    body = models.TextField(help_text=_("Paste the text here."),
                            verbose_name=_('text'))  # HTML
    # todo probably should delete this field and create a special form in admin

    author = models.CharField(
        max_length=50,
        help_text=_("Enter author's first and/or  second name."),
        verbose_name=_('author'))
    filename = models.CharField(
        max_length=1000,
        help_text=_(
            "Enter the name of the file from which the text is taken."),
        verbose_name=_('file name'))

    audio_file = AudioField(db_index=True,
                            null=True,
                            upload_to='audio/',
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text="Allowed types - .mp3, .wav, .ogg")

    image_file = models.ImageField(upload_to='images/',
                                   null=True,
                                   blank=True,
                                   help_text="Allowed types - .jpg .png")

    transcript = models.TextField(help_text=_("Enter transcript."),
                                  verbose_name=_('transcript'))

    # optional fields - need them for meta in CoRST
    date = models.DateField(
        db_index=True,
        null=True,
        blank=True,
        help_text=_("When the work on the text started, e.g. 2014."),
        verbose_name=_('date'))
    gender = models.CharField(max_length=1,
                              null=True,
                              blank=True,
                              choices=((u'ж', _(u'женский')), (u'м',
                                                               _(u'мужской'))),
                              db_index=True,
                              verbose_name=_('gender'))
    type_of_task = models.CharField(max_length=50,
                                    null=True,
                                    blank=True,
                                    db_index=True,
                                    verbose_name=_('type_of_task'))
    birth = models.IntegerField(null=True,
                                blank=True,
                                help_text=_("Year of the author's birth"),
                                verbose_name=_('birth'))
    grade = models.IntegerField(null=True, blank=True, verbose_name=_('grade'))
    city = models.CharField(max_length=50,
                            null=True,
                            blank=True,
                            verbose_name=_('city'))

    # needed for general corpus statictics
    words = models.IntegerField(editable=False,
                                null=True,
                                blank=True,
                                verbose_name=_('number of words'))
    sentences = models.IntegerField(editable=False,
                                    null=True,
                                    blank=True,
                                    verbose_name=_('number of sentences'))

    # needed for annotation statistics
    annotated = models.BooleanField(default=False,
                                    verbose_name=_('text is annotated'))
    checked = models.BooleanField(default=False,
                                  verbose_name=_('text is checked'))

    def __unicode__(self):
        return self.title

    def save(self, **kwargs):
        handle_sents = False
        if self.id is None:
            handle_sents = True
        super(Document, self).save()
        # todo how to close body change after a Document has been created?
        # we don't want people to change the texts after it has been parsed and loaded to the DB
        # but we want them to be able to edit meta
        if handle_sents:
            pass
            self.handle_sentences()

    def handle_sentences(self):
        self.words, text = mystem(self.body)
        self.sentences = len(text)
        super(Document, self).save()
        for sent_id in range(len(text)):
            sent, created = Sentence.objects.get_or_create(
                text=text[sent_id].text, doc_id=self, num=sent_id + 1)
            words = text[sent_id].words
            stagged = []
            for i_word in range(len(words)):
                sent_pos = ''
                if i_word == 0: sent_pos = 'bos'
                elif i_word == len(words) - 1: sent_pos = 'eos'
                token, created = Token.objects.get_or_create(
                    doc=self,
                    sent=sent,
                    num=i_word + 1,
                    sent_pos=sent_pos,
                    token=words[i_word].wf,
                    punctr=words[i_word].pr,
                    punctl=words[i_word].pl)
                analyses = words[i_word].anas
                all_ana = words[i_word].tooltip
                for ana in analyses:
                    lem = ana[0]
                    bastard = False
                    if 'qual="' in lem:
                        lem = lem.split('"')[0]
                        bastard = True
                    lex, gram = ana[1].split('=')
                    if ',' in lex:
                        lex = lex.split(',')
                        gram = ','.join(lex[1:]) + ',' + gram
                        lex = lex[0]
                    if bastard:
                        gram = 'bastard,' + gram
                    Morphology.objects.get_or_create(token=token,
                                                     lem=lem,
                                                     lex=lex,
                                                     gram=gram)
                word = ' <span class="token" title="' + all_ana + '">' + \
                       token.punctl + token.token + token.punctr + '</span> '
                # todo rethink this piece
                # Tim says storing html is fine, since you never change it later and they do it in EANC, for example
                # but still, there must be a better implementation - absolutely not urgent
                stagged.append(word)
            sent.tagged = ''.join(stagged)
            sent.save()

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = os.path.join(settings.MEDIA_URL, str(self.audio_file))
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (
                file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = 'Audio file'

    def image_img(self):
        url = os.path.join(settings.MEDIA_URL, str(self.image_file))
        if self.image_file:
            return '<img src="{}" width="100%" onclick="location=\'{}\'"/>'.format(
                url, url)
        else:
            return '(none)'

    image_img.allow_tags = True
    image_img.short_description = 'Image'

    class Meta:
        verbose_name = _('document')
        verbose_name_plural = _('documents')
예제 #19
0
class Question(models.Model):

    question_no = models.IntegerField(blank=False)
    question_text = HTMLField()
    hint = HTMLField()
    image = models.FileField(upload_to=upload_location, null=True, blank=True)
    thumbnail = models.FileField(upload_to='thumbs', editable=False)
    audio_file = AudioField(upload_to=upload_location_audio,
                            blank=True,
                            ext_whitelist=(".mp3", ".wav", ".ogg"),
                            help_text=("Allowed type - .mp3, .wav, .ogg"))

    # choices = models.ManyToManyField('Choice')

    mocktestsubsection = models.ForeignKey(MockTestSubSection,
                                           on_delete=models.CASCADE)
    mocktestsentence = models.ForeignKey('MockTestSentence',
                                         on_delete=models.CASCADE,
                                         blank=True,
                                         null=True)

    # correct_answer=models.CharField(max_length = 1)

    # deleted = models.BooleanField(default=False, blank=True)
    date_created = models.DateField(auto_now_add=True)
    date_updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        return "%s. %s" % (self.question_no, self.question_text)

    def save(self, *args, **kwargs):
        """
        Make and save the thumbnail for the photo here.
        """
        super(Question, self).save(*args, **kwargs)

        if self.image:
            if not self.make_thumbnail():
                raise Exception(
                    'Could not create thumbnail - is the file type valid?')

    def make_thumbnail(self):
        """
        Create and save the thumbnail for the photo (simple resize with PIL).
        """

        image = Image.open(self.image)
        image.thumbnail(THUMB_SIZE, Image.ANTIALIAS)

        thumb_name, thumb_extension = os.path.splitext(self.image.name)
        thumb_extension = thumb_extension.lower()

        thumb_filename = thumb_name + '_thumb' + thumb_extension

        if thumb_extension in ['.jpg', '.jpeg']:
            FTYPE = 'JPEG'
        elif thumb_extension == '.gif':
            FTYPE = 'GIF'
        elif thumb_extension == '.png':
            FTYPE = 'PNG'
        else:
            return False  # Unrecognized file type

        # Save thumbnail to in-memory file as StringIO
        temp_thumb = BytesIO()
        image.save(temp_thumb, FTYPE)
        temp_thumb.seek(0)

        # set save=False, otherwise it will run in an infinite loop
        self.thumbnail.save(thumb_filename,
                            ContentFile(temp_thumb.read()),
                            save=False)
        temp_thumb.close()

        return True

    def audio_file_player(self):
        """audio player tag for admin"""
        if self.audio_file:
            file_url = settings.MEDIA_URL + str(self.audio_file)
            player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (
                file_url)
            return player_string

    audio_file_player.allow_tags = True
    audio_file_player.short_description = ('Audio file player')