Tagged Questions
2
votes
1answer
42 views
cancatenate two strings in a dict
views.py
def method(request):
for member in list:
personname = {'id':member.id,
'name':member.firstname + member.lastname
}
...
1
vote
0answers
32 views
Django invite friends from social account
I'm using social_auth API for login using social account. Is there is any possibilities to invite friends via facebook, twitter, linkedin in social-auth. or any other way to invite friends from social ...
1
vote
1answer
27 views
send report in specific json format
views.py
def json(request):
defaultnumber = []
phoneinfo = PhoneInfo.objects.filter(user = user_id)
for phone in phoneinfo:
phone_no = {'id':some.id,
...
0
votes
2answers
31 views
compare two fields data from database
models.py
class ReportType(models.Model):
report = models.ForeignKey(Report)
title = models.CharField('Incident Type', max_length=200)
class Report(models.Model):
user = ...
1
vote
2answers
39 views
What's the best way to orgaize relations in django? Flat or tree -like?
I got 3 models
client
loan
installment - one part of loan
shold i do:
loan-foreignKey(client)
installment-foreignKey(loan)
and to get the client installments something like that:
loans = ...
0
votes
1answer
26 views
TypeError: 'BaseQuery' object is not callable Flask
I am getting an error like TypeError: 'BaseQuery' object is not callable
Here is my code:
companies = Company.query.all()
return Company.query(func.count(Company.id))
I need to find out number ...
0
votes
1answer
43 views
Django: How do I get a nested foreignkey to continuously display?
For academic purposes, I am creating software that can manage a company's clients, project, and staff members. I figured out that by referencing a foreignkey in a separate model, you can get two ...
-1
votes
1answer
19 views
Satchmo clonesatchmo.py ImportError: cannot import name execute_manager
I get satchmo to try, but I have a great problem at first try, and I don't understand whats wrong.
When I making $ python clonesatchmo.py into clear django project, it trows an error:
$ python ...
0
votes
1answer
16 views
Django ManyToMany with through model implementation
So let's say I have these models in my Django app:
class Ingredient(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class ...
0
votes
2answers
85 views
search() takes exactly 2 arguments (1 given)
views.py
def search(request,csv_export):
if request.method == 'POST':
reports = Report.objects.filter(user__in=user_list).order_by('-created_date_time', '-id')
'''''
some code
...
0
votes
1answer
38 views
Define CSS style in Django model field
Suppose I have a following code:
File models.py:
from django.db import models
from django.contrib.auth.models import User
class MyClass(models.Model):
username = models.ForeignKey(User, ...
0
votes
1answer
30 views
User.DoesNotExist - catch exception value
I am trying to write a confirm function to confirm the registration by a user.
Simple logic: A user registers and gets an email. During registration I create hash value to make sure all users have ...
1
vote
4answers
48 views
Returning a Unicode string vs. Returning a normal string encoded as UTF-8?
On the tutorial page for the Django web framework, the author explains why adding a __unicode__() method is preferred than a __str__() with the following reason:
Django models have a default ...
0
votes
0answers
24 views
Django unique_together breaks group_by with annotate(Count('column'))
I'm using Django 1.5 and my Django model looks something like this:
class MyModel(models.Model):
other_model = models.ForeignKey(OtherModel, related_name='%(class)s_set')
number = ...
1
vote
1answer
30 views
django integrity error, i know why, but dont know how to solve
I changed my former user model so that now it inherits from django's user model.
from django.contrib.auth.models import User
class UserProfile(User):
#fields..
but other models were pointing to ...
0
votes
0answers
20 views
user_id not in auth_user table after changing UserModel
I have had normal custom user model. I have many users also in database and other models pointing to this user model. Now i changed the user model so that it inherits from django's user model.
I did ...
0
votes
0answers
27 views
Django-Grappeli: Maximum recursion depth exceeded
I have installed Grappelli Cms of Django.As https://django-grappelli.readthedocs.org/en/2.4.5/quickstart.html#installation
After that installation,when I call the admin page the error is: ...
0
votes
2answers
41 views
Django datetime primary key doesn't constrain unique
So, here's my model:
class MyModel(models.Model):
timestamp = models.DateTimeField(primary_key=True)
fielda = models.TextField()
When I call syncdb, django doesn't add a constraint to ...
0
votes
1answer
66 views
checkbox checked on pageload and form post
forms.py
class SearchKeyword(Form):
status = forms.BooleanField(widget=forms.CheckboxInput(attrs={'onclick':'this.form.submit();','id':'status'}),required=False,initial=True,label="Status")
...
0
votes
0answers
31 views
Not able to show all reports for limited account holder
models.py
class Members(models.Model):
user = models.ForeignKey(User, related_name = 'user_list' )
member = models.ForeignKey(User, related_name = 'memer_list' )
views.py
...
0
votes
0answers
25 views
Admin Site Customisation using many-to-many recursive models in Django 1.4 and querying questions
I have this in models.py of accounts app, I have a UserProfile class so that I can add more fields to the normal User class. I also create a UserFollowing class(table) which stores the user_id of the ...
2
votes
4answers
39 views
Integer field prefix zero not displaying
forms.py
class PhoneForm(forms.ModelForm):
number1 = forms.IntegerField(required=False,error_messages={'invalid':'Enter a valid phone number'})
number2 = ...
2
votes
1answer
27 views
Loading fixture with many-to-one relations in Django
The Django tutorial on djangoproject.com gives a model like this:
import datetime
from django.utils import timezone
from django.db import models
class Poll(models.Model):
question = ...
1
vote
1answer
21 views
Editing the model object with update view django by excluding fields
I am trying to Edit/Update a model object(record) using django Updateview
model.py
from django.db import models
from myapp.models import Author
class Book(models.Model):
author = ...
1
vote
3answers
273 views
Ajax succesfull call show div with form data
ajax:
$('.openDiv').click(function (e) {
e.preventDefault();
var csrf_token = $("#csrf_token").val();
var id = $(this).closest('td').attr('id');
var firstname = ...
0
votes
1answer
34 views
issue in if condition loop
template.html
In django is it possible to check condition like this,I am getting error in this line (incident.other_location or location).
{%if newreport_tab and reportperson and ...
0
votes
1answer
31 views
How to open a form in editable mode
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
phone_daytime = models.CharField(max_length=50, null=True, blank=True)
class User(models.Model):
first_name = ...
0
votes
1answer
52 views
django - Use foreign key for multi-table inheritance
I am stuck in an odd position in my database design, and I would appreciate some comments. We are using django-shop for an e-commerce platform. There is a base class defined for products:
from ...
0
votes
1answer
31 views
django user_passes_test decorator is_superuser
Initially i was restricting the permission for all user with the help of is_superuser flag,and i used @user_passes_test(lambda u: u.is_superuser) decorator.Now i am not using is_superuser flag and ...
0
votes
1answer
24 views
In Django is it possible to default an integer field based on a float field?
Looking to create default based on another field, something along the lines of:
class Track(models.Model):
distance = models.FloatField()
timeout = ...
1
vote
1answer
47 views
Django Query only one field of a model using .extra() and without using .defer() or .only()
I'm using django ORM's exact() method to query only selected fields from a set of models to save RAM. I can't use defer() or only() due to some constraints on the ORM manager I am using (it's not the ...
2
votes
1answer
28 views
Passing np.array indexes into functions
I have a Django model which provides access to numpy array.
I want to create a generator which accepts two arguments:
A Queryset of the model I just mentioned, and
A numpy array slice/index syntax
...
3
votes
1answer
27 views
Django filter on related field using annotate
I want to filter using annotate.
Here is my code:
class Blog(models.Model):
name = models.CharField(max_length=100)
class Reader(models.Model):
name = models.CharField(max_length=50)
...
0
votes
2answers
126 views
create row of date while creating superuser
models.py
TITLE = (
('Classroom', 'Classroom'),
('Playground', 'Playground'),
('Staff Room','Staff Room'),
)
class Location(models.Model):
user = models.ForeignKey(User,null=True)
...
2
votes
1answer
43 views
Django User Sessions, Cookies and Timeout
I'm working with a Django application and my current goal is to keep track of the user session with cookies. I have a feeling that, as always, my understanding is a bit off with regards to how I do ...
1
vote
1answer
34 views
Is it possible to add a datetime column to a manytomany field?
I was wondering if there was a way to add a datetime auto_now_add=True column to a manytomany field.
I have the following model.
class Photographer(models.Model):
user = ...
1
vote
1answer
23 views
Trigger An Action Based on value change of DateTimeField in Django
I would like to fire an event immediately at/after a certain DateTimeField in a certain model equals the value of datetime.now(). It is a field that marks expiration of a product, so as soon as it ...
1
vote
1answer
35 views
convert database object to string in django
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
security_question = models.CharField('Question', max_length=255, null=True, blank=True)
security_answer = ...
0
votes
0answers
42 views
from django.db import models is broken in a django standalone crontab script
Before posting this, i'ved tried a wide variety of possibilities for getting this custom script to work (with no success). I have a script in a /lib directory which is being run in the crontab every X ...
0
votes
0answers
22 views
Load dropdown onchange of anyother value inside modelform class
Can we load values of a dropdown dynamically onchange of an event.
Let me explain through an example:
I am using a model form to dislplay a certain form, below is my form class
class ...
2
votes
1answer
48 views
Django admin encoding error
I am trying to add new user with admin interface and get this error:
IntegrityError at /admin/main/customuser/add/
������������: INSERT ������ UPDATE �� ��������������
"django_admin_log" ...
1
vote
2answers
33 views
Finding matches in Django model without punctuation or spaces
I'm trying to match a string that is a GET from the URL, to a field in the database that is the same string without any punctuation or spaces. For example:
URL: http://www.mysite.com/JohnBSmith/
And ...
1
vote
1answer
27 views
issue in search and display the report
views.py
def search(request):
"""""""
if 'search' in request.POST:
search_keyword = request.POST.get('search_keyword')
reports = ...
0
votes
1answer
34 views
Django save or update model
I am using Django 1.5.1 and I want to save or update model.
I read the django document and I met the get_or_create method which provides saving or updating. There is a usage like;
...
0
votes
2answers
39 views
how to set username in user model to a random string
views.py
def index(request):
registerform = UserRegisterForm()
if request.method == 'POST':
if 'password' in request.POST:
registerform = UserRegisterForm(request.POST) ...
0
votes
3answers
58 views
Django .is_superuser field permission
By default from project directory by running manage.py createsuperuser command I am able to create a superuser, but the .is_superuser flag is the default django flag to differ superuser or other user.
...
0
votes
2answers
38 views
Django Model Class Missing in Admin
For some reason, the classes archive and album show all of their fields in the django admin panel, but image isn't showing an album field when I go to add an image to the image panel. If I open a ...
0
votes
0answers
29 views
Django FieldError and AttributeError exceptions after adding new field to model
I'm writing a multipurpose web application, and the data model is somewhat in flux.
I have a class Client defined as
class Client(models.Model):
client = models.IntegerField(primary_key=True, ...
1
vote
2answers
40 views
Django model export on MySql server
I imported the external database into my project , thereby converting it to models.py file using python manage.py inspectdb > models.py command.
Now I have edited the models.py file by adding ...
-2
votes
1answer
28 views
How to add django model fields after definition
I have a simple django model:
class Country(models.Model):
name=models.CharField(max_length=500)
iso_alpha3=models.CharField(max_length=3)
I need to add a new field 'default_city' after the ...