Django account group by date from datetime

I'm trying to count the dates users register from a DateTime field. In the database this is stored as '2016-10-31 20:49:38' but I'm only interested in the date '2016-10-31'. The raw SQL query is: select DATE(registered_at) registered_date,count(regis

JetBrains Pycharm - Error while debugging my project

I just switched to Mac from windows. I imported my project in pycharm from GitHub but it is giving unknown errors. Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10b75f6a8> Traceback (most recent call las

Django. Delete an object from the query set

I need to do something like this: quito = queryset.get(lugar="Quito") queryset.pop(quito) But I get the error: 'QuerySet' object has no attribute 'pop' How can I solve this?'QuerySet' object has no attribute 'pop' You can see the details about Q

Django: Filter a QuerySet and select foreign key results

In Django, I have two models: class A(models.Model): # lots of fields class B(models.Model): a = models.ForeignKey(A) member = models.BooleanField() I need to construct a query that filters B and selects all A, something like this: result = B.objects

Django ManyToManyField delete through templates

I've the below inefficient 'destroy' method for deleting Ratings that are held in Stimulus which itself is held within Experiment (I have simplified my models, for reasons of clarity). Could you advise on a more efficient way of achieving this? class

Django important models from the model

In my django project, I have a base.html from which all my templates {% extends 'base.html' %}. In that base template I want to do this to a list of all my algorithms. {% for algorithm in algorithms %} # list them out as links in nav bar {% endfor %}

dynamic forms django - Dynamic ChoiceField

In django, how can I make a selectible formField to access the db for every time it is being calld? Right now the line : status = forms.ChoiceField(choices=FormsTools.StatusesToTuples(Status.objects.all())) is executed once django is loaded and not e

Check if an M2M relationship exists

Basically, I have two models, Profile and Event. The Profile has an ownedEvent M2M to the Event table. The model looks like this: class Profile(models.Model): user = models.OneToOneField(User) name = models.CharField(max_length=50) eventList = models

Date ValidationError in Django

I want to block users whose premium plan has expired after 30 days(though I might change the days later). And redirect them to the payment page. I'm doing this by checking the db if the expiry date has reached so it can block them from viewing exclus

Django import error: no module named templates

I keep receiving the error Could not import movies.views. Error was: No module named models Here is my traceback: Environment: Request Method: GET Request URL: http://localhost:8000/movies/awesome-movie/ Django Version: 1.3.1 Python Version: 2.7.3 In

Django post_save () implementation

I have a question about django. I have ManyToMany Models here class Product(models.Model): name = models.CharField(max_length=255) price = models.DecimalField(default=0.0, max_digits=9, decimal_places=2) stock = models.IntegerField(default=0) def __u

How to add data to the database?

How can I add data to my database? My form: from django import forms class DinnerForm(forms.Form): name = forms.CharField(max_length=100) text = forms.CharField(max_length=255) and model: class Dinner(models.Model): name = models.CharField(max_length

Django Querying Relationship Relationship

I'm stuck on a Django ORM issue that is bugging me. I have a set of models linked by a foreign key but the requirements are a bit odd. I need to list items by their relation's relation. This is hard to explain so I've tried to depict this below, give

Django updates the entry

How come it is not possible to save the entry when I fetch it by using filter? It works if I fetch it with get. I need to use filter since I'm using the serializer to return a JSON object. And Django's serializer doesn't like if it is not a QuerySet.

How to configure django-uploadify for downloading videos only?

I want to use django-uploadify to upload for videos only, I just want it to upload videos only, all kind of videos, or at least all kind of popular video formats. So far, i added uploadify in and in I added this (r'^uploadify/',in

django - initialize model fields including manytomanyfields

All, I have a set related models: class Foo(models.Model): fooName = models.CharField() bars = models.ManyToManyField("Bar") class Bar(models.Model): barName = models.CharField() When I create a new one, I would like for it to have a default set

Django query for 3 tables

I have the following model structure Country, City(fk=country) and School(fk=city). Now I want to get list of countries with city, if city has a school. In my template, I want to do for country in countrylist for city in getcitieswithschool Can I get

The model is AlreadyRegistered at /

I'm getting an error: AlreadyRegistered at / The model Post is already registered Why is this happening, and how do I fix it? Here's my : from django.db import models from django.contrib import admin class Post(models.Model): title = models

Different models sharing an ID list

In my application I've added a "Facebook Comment Box" (on different pages, for different objects). Each object has its own comments list so I need to provide a unique (across the site) ID for every single one of them. What would be the best appr

Django: limitation of model data

I'm searching in a way to limit the queryset which I can get through a model. Suppose I have the following models (with dependencies): Company |- Section | |- Employee | |- Task | `- more models... |- Customer | |- Contract | |- Accounts | `- other g

Is it possible to join model types in Django into one object?

For example I have two model objects, Person and Address. Address has a reference to a Person id. What would a query look like that pulls them out together as one object, or is that not possible to do with Django?Have a read of the Django docs on rel

Insert language characters in Django

I am following the link Basically i am trying to insert hindi characters into mysql db I have created the files in the test directory as in the above said link and using django version 1.1 an dpytho

Convention to verify the existence of a Django model?

What is the accepted way of checking a model's existence in a Django app? I've seen this method used: def profile_exists(user): try: UserProfile.objects.get(user = user) return True except: return False Is there a built-in function suited for this pu

Add a field to the template, such as annotate

For example, I have a model Posts and Comments. Post.objects.annotate(Count('comment')) I am making such query to get count of comments for every post. But in template i should check if this value greater than 4. As I know there is no such templateta