P
P
Pavel Dyukarev2017-10-28 21:37:05
PostgreSQL
Pavel Dyukarev, 2017-10-28 21:37:05

How to store mp3 files in django?

I drink the application. The idea is "Photos are accompanied by a voice description." i.e. when the user creates an entity called "story" - he uploads a photo and description (in mp3).
So the essence of the "History from Paul" consists of a general title + a photo with an audio description (there can be many such bundles of photos + description).
Here are the models I created:

from django.db import models

# Create your models here.
class Account(models.Model):
    login = models.CharField(primary_key=True, max_length=30)
    password = models.CharField(max_length=30)

    def __unicode__(self):
        return self.login


class Story(models.Model):
    login = models.ForeignKey(Account) # добавляем поле логин из таблицы Account
    story_id = models.CharField(unique=True, max_length=30)
    story_color = models.CharField(max_length=16, default=0)
    head = models.CharField(max_length=100)
    main_mp3 = models.CharField(max_length=300)

    def __unicode__(self):
        return self.story_id


class Story_Segment(models.Model):
    story_id = models.ForeignKey(Story)
    voice = models.CharField(max_length=300)
    photo = models.CharField(max_length=300)

    def __unicode__(self):
        return self.story_id

After a long search on the net, I could not find an instruction in the style of BestPractise: how to store mp3 files.
I saw the phrase that the mp3 files themselves need to be stored in the project folder and just throw a link to the project into the database.
And I saw that someone advises storing files directly in the database (here I became completely scared) I
use PostgreSQL database.
If anyone has come across this problem, please help with concrete advice.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2017-10-28
@PavelDuk

#class Account(models.Model)
from django.contrib.auth.models import AbstractUser
class Account(AbstractUser):

#class Story_Segment
class StorySegment(models.Model):
  story = models.ForeignKey(Story)
  voice = models.FileField(upload_to='uploads/')
  photo = models.FileField(upload_to='uploads/')


#story_id = models.CharField(unique=True, max_length=30)
story = models.ForeignKey(Story)

#def __unicode__
def __str__

N
Nobby2519, 2017-10-29
@Nobby2519

What is the best way to store many files - in a database or as files?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question