Questions tagged [django-2.x]
15 questions
2
votes
1 answer
how to dynamicaly create models in tests?
I would like to test my custom subclassed Django model field. I could use existing models from my project but they are quite complicated and hard to setup.
I have found two SO question but the are quite old (2009 and 2012).
#1 #2
So I wanted to ask…

Jan Kaifer
- 664
- 4
- 18
1
vote
1 answer
ModelForm returns None even fields has value
I've been searching of why modelforms fields model returns None even it has a value given in the fields.
Form
class GoodMoralSettingForm(CrispyFormMixin, forms.ModelForm):
class Meta:
model = Student
fields = [
…

denmg
- 360
- 3
- 12
1
vote
1 answer
Pagination not working for viewsets in django rest_framework
paginate.py
class StandardResultsSetPagination(PageNumberPagination):
page_size = 3
page_size_query_param = 'page_size'
max_page_size = 5
Serializers.py
class AreaUsersSerializer(serializers.ModelSerializer):
class Meta:
…

Chetan Vashisth
- 438
- 4
- 14
1
vote
0 answers
CustomUser on separate database issues
I want to use the users from a legacy database but keep everything else on the 'default' database.
The main issue I have atm is that I can't get the database router to properly forward queries to the appropriate database. Namely when I run the…

Pithikos
- 18,827
- 15
- 113
- 136
1
vote
1 answer
IntegrityError at /home/create/ (1048, "Column 'country_id' cannot be null")
I'm trying to create news directly on the webpage using Django 2.7, but have a problem with adding categories and countries IntegrityError at /home/create/ (1048, "Column 'country_id' cannot be null")
Here is my code:
home/models.py
class…

Misha Ronchik
- 11
- 1
0
votes
2 answers
Rest Framework - Many 2 Many relation, include through model fields in API
I have 2 models connected via M2M model:
class Person(models.Model):
name = models.CharField(max_length=30)
class Group(models.Model):
name = models.CharField(max_length=100)
members = models.ManyToManyField(Person,…

Sourabh
- 21
- 4
0
votes
1 answer
Django authentication login() returns anonymous user
I am trying to log in to a database that is not the default database, and for that I've wrote a custom authentication code but whenever I try to login the method returns an AnonymousUser. I've no idea why is it doing so because user authentication…

Shaikh Abuzar
- 101
- 1
- 9
0
votes
2 answers
How to use model objects as choices for django-filter MultipleChoiceFilter
I'm using Django-filter, and I would like one of the fields (supervisor) to be a ChoiceFilter where the choices are objects from the model. What's the most efficient way to do that? I tried following this post, but kept getting errors no matter what…

Evan
- 1,960
- 4
- 26
- 54
0
votes
1 answer
Django - Find position of a record in a filtered list
I have a Django app in which I have a DetailView Page. I also have a ListView which is paginated and also has a created by filter (only author can see the records added by herself). I want to pull a position in ListView of the record being displayed…

Parry
- 177
- 3
- 16
0
votes
1 answer
Going back to right page in paginated list of Django ListView from Django DeleteView
I have a simple CRUD application with following model, List View and DetailView, where ListView is paginated by 5 items per page.
I want to put a back button on DetailView such that it will take me back to the page of ListView from which DetailView…

Parry
- 177
- 3
- 16
0
votes
1 answer
Redirect back to previous page django
I am building a django app for which one component is simple CRUD for some models. I have created add, edit, delete, view details and listing pages. I have given the buttons to edit and delete records on listing page as well as view details page.…

Parry
- 177
- 3
- 16
0
votes
1 answer
Django OneToOne Reverse Relation gives RelatedObjectDoesNotExist if though it exists
I have the following models
class SimulationStatus(models.Model):
simulation = models.ForeignKey(Simulation, on_delete=models.CASCADE)
name = models.CharField(
max_length=80,
choices=SimStatusOptions.to_sequence()
)
…

LarsVegas
- 6,522
- 10
- 43
- 67
0
votes
1 answer
change verbose name of VISIT SITE in django 2.x admin
I only seem to find answers around changing the actual link of VISIT PAGE. How however can I change the verbose name to e.g. HOMEPAGE?
Below code only changes the actual link:
class AdminSite:
admin.site.site_url = "/hompeage"
What I'd like to…

Aaron Scheib
- 358
- 4
- 18
0
votes
0 answers
Recreate SQL Commands from db
I have created a db long ago using django. Now as we are migrating the application, so I need all the CREATE TABLE sql queries which django might have run to create the entire db for our service (which has around 70-80 tables and each table has avg…

Laxmikant
- 2,046
- 3
- 30
- 44
0
votes
1 answer
Get the value of name key from the list of dictionaries return by the annotate and then sort by name?
My Code
def get_areas(self, obj):
text = []
if obj.areas and not obj.areas == []:
print(json.loads(obj.area_count))
print(type(obj.area_count))
return json.loads(obj.area_count)
return…

Chetan Vashisth
- 438
- 4
- 14