Tagged Questions
0
votes
1answer
16 views
'Permission' instance expected, got … Permission instance?
I try to write data migration code for custom user type but when I try to apply migration I get this:
TypeError: 'Permission' instance expected, got <Permission: my_app | Some Text | Can add ...
0
votes
1answer
36 views
Thumbnails are created on each model save()
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name="person")
image = models.ImageField(upload_to='site-media/media/userimages/', default = ...
0
votes
1answer
28 views
How to update multiple objects and increment from 0 to first if filtered to last
How to update all existing objects of model sequentially.
For example, have object with customids 1, 2, 3, 4, 5.
Delete customid 3, I then need to revalue the rest.
increment = 0
for obj in ...
0
votes
2answers
27 views
Accessing Foreign Key values from a foreign key referenced model in django
Models
class Ride(models.Model):
type = models.BooleanField(default=False)
ride_comment = models.TextField(null=True,max_length=140,blank=True)
def __unicode__(self):
return ...
1
vote
1answer
23 views
Django-storage - How to check file size prior to upload?
Storage and Django 1.6:
I want to restrict filesizes saved to s3. What is the appropriate way to do this?
Should I just do custom field validation in the form or is there a better way to do this when ...
2
votes
2answers
62 views
Custom user model in django
I want to create a custom user model using django.contrib.auth.models.AbstractUser as stated in the djangodocs:
If you’re entirely happy with Django’s User model and you just want to add some
...
0
votes
1answer
22 views
Why do model mixins break django-mptt foreign keys?
I'm modifying a third-party Django app based on django-mptt. I'm trying to refactor one monstrously big model into a base class and a set of mixins. All seemed well, however...
class ModelMixin([see ...
1
vote
0answers
17 views
django admin form with predefined inlines
The problem is to have the inline models to have some of theirs fields preselected according to other model.
Let's make an example:
class Document(models.Model):
DOC_TYPES = ((DC1, 'Doc type ...
0
votes
1answer
22 views
Export Django Database into YAML file
I know you can easily import a YAML file into a Django database (in order to populate the database before starting the project for instance) but how can I do the opposite (ie save the complete ...
0
votes
0answers
27 views
how to add button on model level in django?
I am customizing django admin panel for that I have extended change_form
{% extends "admin/change_form.html" %}
{% block after_field_sets %}{{ block.super }}
<ul class="object-tools">
...
0
votes
3answers
22 views
where django store request['user'] in what file
As mentioned in the documentation, authenticated user's object is stored within user variable in templates. i need where django stored user variable in apps file thanks:
user = request.user
...
0
votes
1answer
59 views
ImportError: cannot import name <model_class>
I am using forms.ModelChoiceField to have the choice loaded from a specific model entries:
from order.models import Region
class CheckoutForm(forms.Form):
area = ...
0
votes
1answer
34 views
Dynamic Fields with ManyToMany in Django admin
I want to define some fields for my model in another model. Here:
class Setting(models.Model):
name = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class ...
1
vote
1answer
33 views
How to dump json of last 30 minutes updates of django model?
I want to dump json of last 30 minutes updates in a model/table.
I used the code bellow, but its not giving me desired result.
Its always giving me the last/recent(1 object) update instead of 30 ...
0
votes
2answers
57 views
How to make an auto increment integer field Django
the question is simple, I am making an order for shopping cart and I need to make a field that auto increments when the order is made. But I don't know how to make the integer field auto increment :S ...
0
votes
1answer
18 views
Group by FK field
I have the following models:
class Website(models.Model):
name = models.CharField(max_length=256, unique=True)
class Product(models.Model):
website = models.ForeignKey('Website')
name = ...
0
votes
1answer
34 views
How would I use the objects from a related Model to populate the initial value of a Field in a ModelForm?
My issue is with the 5th line below (the one with all of the question marks):
class EditProfileForm(forms.ModelForm):
""" Base form used for fields that are always required """
first_name = ...
0
votes
1answer
33 views
Django ModelForm passing multiple ManytoMany that are using through?
I am trying to figure out how to get two things figured out with Django (1.6) forms. I am looking to create a form using ModelForm with a model that has more then one ManyToManyField using through. I ...
0
votes
1answer
27 views
NotImplementedError Django Command
I created a simple django command and when I want to test it from the command line (terminal) I get a NotImplementedError.
My code:
from django.db import models
from django.core.management.base ...
1
vote
4answers
36 views
Django - Function inside a model. How to call it from a view?
I'm designing a model in Django but I don't know if this is the best way. I have a model called "History" and inside this model I've a specialized function that will handle the inserts to this model.
...
2
votes
2answers
37 views
How can one assert in Django that a model field has already been populated from the DB?
In Django, is there an easy way to test that a model field on an object has already been queried from the database (e.g. an object coming from a foreign-key relationship)?
I would like to make an ...
2
votes
2answers
26 views
How to check django model data type?
I have a django model consist of 140 columns which contain 10 date types, 60 char types, 70 number types.
class SOA_detail(models.Model):
...
Is there a way to group up by data types and place ...
0
votes
1answer
33 views
Django inserts new object after save() method instead of update
When trying to update an existing Django model object (with the save() method), a new row is inserted instead.
For example:
>>> import datetime
>>> from data_lib.models import ...
1
vote
1answer
32 views
How does django interpret CommaSeparatedIntegerField 'max_length' field option?
In django model types, models.CommaSeparatedIntegerField consists of a field of integers separated by commas with a required max_length field option.
If i have max_length=30, does it mean i can ...
0
votes
1answer
27 views
How to cache a paginated Django queryset
How do you cache a paginated Django queryset, specifically in a ListView?
I noticed one query was taking a long time to run, so I'm attempting to cache it. The queryset is huge (over 100k records), ...
1
vote
2answers
15 views
Django model latest() method
I am having the following issue (BTW I think I had not had this problem the day before):
>>> rule = Rule.objects.get(user=user)
>>> rule.id
1
>>> rule = ...
0
votes
1answer
14 views
Building 'limitless' menu trees with Django
I have a model:
menuName = models.CharField(max_length=50)
menuAlias = models.CharField(max_length=50, unique=True, validators=[aliasvalidator])
published = models.BooleanField()
parentId = ...
1
vote
1answer
45 views
Django model save method, updating m2m does not work
I need to prevent user from self-killing from administrators list in the model:
class Organization(models.Model):
administrators = models.ManyToManyField(User, blank=True, null=True, ...
0
votes
1answer
23 views
How to not display foreign key as list in Django admin object page?
I have two basics models:
class Address(models.Model):
...
class Company(models.Model):
address = models.ForeignKey(Address, related_name='address')
billing_address = ...
0
votes
1answer
28 views
Model has either not been installed or is abstract
When I try to migrate my code I get this error.
Here are my code and classes:
from django.db import models
from core.models import Event
class TicketType(models.Model):
name = ...
0
votes
1answer
21 views
how to extend/override UserManager
Am on Django 1.6
In my app I'd like to have a User object and a separate profile object. I'd like to avoid implementing a custom User object and instead just use a one-to-one relation to a model that ...
1
vote
2answers
34 views
How to make this django model query
My model looks something like this:
uri
-----
1@domainXY
2@domainYZ
3@domainZK
I want to match username parts of this uris to some list. So if there is no @domain part of the uri, I would type:
L ...
0
votes
1answer
18 views
Binding ModelForm to Model's instance when saving
Suppose I have a model Article and its ModelForm ArticleForm.
>>> a_form = ArticleForm({"headline" : "My headline"})
>>> b = Article()
>>> b.save()
Now I would like to ...
1
vote
2answers
53 views
Django - query for to give rows where one column Not equals to another column in same model
My model have 3 fields
class Table(models.Model):
in_time = models.DateTimeField(null=True, blank=True)
actual_time = models.DateTimeField(null=True, blank=True)
i want to fetch results in ...
0
votes
1answer
30 views
Keeping track of object id in Django view
My view is a function based view (it is a legacy and due to inline formset usage it is easier to keep it that way, rather than CBV). My goal is to be able to render the ModelForm for the model object ...
0
votes
0answers
33 views
How do I put custom user models into Django admin
So, I have a model with 3 custom user classes:
class customUser(AbstractBaseUser):
class customUser(AbstractBaseUser):
class customUser(AbstractBaseUser):
I need all of them to be in Django's ...
0
votes
0answers
38 views
Relationship errors when creating Django Custom User Model
I have been following this guide to creating custom user models in Django. I'm new to Django as a framework, and have become stuck at a series of four errors when trying to follow step eight, in which ...
0
votes
1answer
13 views
DatabaseError at /admin/app1/book/ no such column: app1_book.related_id
I wrote a Django Program for admin. But it turns out the ForeignKey has something wrong, which I can't find out.
Here is my admin.py and views.py:
from django.contrib import admin
from app1.models ...
0
votes
3answers
47 views
save a tuple to a django model
Is there a way to save a tuple to a django model?
example:
Class User(models.Model):
location = models.tupleField()
where User.location = (longitude, latitude)
0
votes
0answers
19 views
Django admin display FileFiled name rather than uploaded_to
Here is a simple django model
class Attachment(models.Model):
arabic_file_title = CharField(max_length=100, blank=True);
arabic_file = FileField(upload_to="attachment/%Y/%m/%d", blank=True)
...
0
votes
0answers
41 views
Date-Time field in Django
I want to provide a functionality to admin from where he can select date and time. I have used model field for that " models.DateTimeField". For Date it works fine but for time it provide only few ...
0
votes
1answer
25 views
Django Class Based View: retrieve lastly viewed entry
I am fairly new to CBV and I have the following question:
I see that there is CreateView that would show you the "empty" form to create a new database entry and there is UpdateView that would show you ...
1
vote
2answers
117 views
Django Model Design using GenericForeignKey
I have a Scheme model that can have 2 rewards assign to it only, one for a member of the scheme and the other for their friend.
Below is how I have design the model for this, but now I'm starting to ...
2
votes
1answer
27 views
Django not seeing Users in database?
I have a database and have the admin interface enabled. When I go to the admin interface and click on 'Users' there is one user whose username is ayman. I am following a tutorial done in a book called ...
0
votes
1answer
21 views
Search on a abstract base class in Django vs concrete (multi-table) inheritance
I currently have an abstract base class that several of my models inherit from. I have run into an issue trying to filter on it.
I was told in Django you can NOT filter on an abstract model and ...
0
votes
1answer
21 views
Django reverse lookup in API
I would like to know how I have get a list of all related animals in my TastyPie api/houses call:
For example:
House Model:
class House(models.Model):
description = ...
0
votes
3answers
40 views
Django - all attributes for the User object?
I am reading a book called 'Packt Publishing, Learning Website Development with Django' and I am doing a tutorial on how to create a bookmarking website where users can read articles and bookmark them ...
0
votes
1answer
18 views
Django - Inserting related instance
I am trying to change how a model saves and add a field automatically. The field in question is a foreignkey.
here is the code:
def save(self, *args, **kwargs):
season = ...
3
votes
1answer
58 views
Django - Boolean field with Single True
I want a boolean field that only allows for ONE of them to be True based on a foreign key (User). I am now sure how to word this or really search for it, but I was able to get a simple implementation ...
0
votes
0answers
27 views
Error while creating a custom widget field in Django
I am trying to create a telephone number field, following Django official documentation, but getting the below exception and I understand it is because of CharField and wanting to convert it to ...