Questions tagged as 'django-models'

1
answer

ModelMultipleChoisefield with unique objects from each user Django

I have a user model that has a ManytoMany () field to another object: class PrivateWallet(models.Model): name = ... class Usuario(AbstractUser): private_wallets = models.ManyToManyField(PrivateWallet, blank=True) and I want to crea...
asked by 14.07.2018 / 22:27
2
answers

MultipleObjectsReturned Django

I want to return the 2 or n records matches that appear but shows me the following exception    Exception Value:       get () returned more than one File - it returned 2! The Query that returns the exception queryModeloArchivo= Archivo...
asked by 27.03.2018 / 19:46
1
answer

Filter by weekend in a certain range of hours. Django

I am trying to make a query that I return the number of orders that your delivery date is during the weekend between 7 am - 11 am and I have been trying this way: Order.objects.filter(delivery__range=[breakfast_start_date, datetime.now()], sta...
asked by 13.03.2018 / 23:07
1
answer

Assign a foreign key from one form to another in django and redirect with reverse_lazy

I have 2 test models, Model1 and Model2. Model2 has the OneToOneField key to Model1, but I can not assign the Model1_id to Model2_id to keep the relationship of the models, I do not know how to access that data from the views.py to assign it in...
asked by 05.03.2018 / 20:33
1
answer

How to save image in django in a folder whose name is the id of the saved object?

I am working on a system where there are real estate companies, which publish real estate and these have cover photos. I need to save the cover images of the properties in a route similar to this: /media/id_de_inmobiliaria/id_inmueble/portada...
asked by 13.02.2018 / 20:06
1
answer

How do I insert a ForeignKey field into a model?

I do not know what I'm doing wrong look at my model.py I'm using a User extending AbstractBaseUser since I wanted to use the email field as an identifier and not the username that comes with the default in fact delete it. Using the admin works p...
asked by 29.01.2018 / 16:01
2
answers

Problem with a Choice [Django - Pyhon]

Good morning! I have a modeo which has a field of type text in which is a "choice". ANUNCIADA = 'A' AMARRADA = 'M' TERMINADA = 'T' ANULADA = 'N' LIST_ESTADOS_ANUNCIOS = ( (ANUNCIADA, 'Anunciada'), (AMARRADA, 'Amarrada'), (TERMINADA, 'Termi...
asked by 02.02.2018 / 19:52
1
answer

ID Alfanumerico Django

good: I'm trying to generate unique ID's with letters and numbers but all the methods I've tried return strings that can give the possibility of repeating and cause the application to fail. Right now I have this: class Comentario(models.Mod...
asked by 26.01.2018 / 17:06
1
answer

Avoid repeated objects in the django database

I have a page that has a form where people can put a name, and create a profile. The problem is when several people try to put the same name, since it gives this error get() returned more than one Person What I'm trying to do is to avo...
asked by 04.08.2017 / 23:06
1
answer

Check dates in Django

I want to obtain data on the same date from this query: Example: fecha_inicio= 06/09/2017 fecha_final= 06/09/2017 query=DetalleParte.objects.filter(fecha_creacion__range=(fecha_inicio,fecha_final) However the Query only brings me da...
asked by 06.09.2017 / 17:24