Skip to content

Magenaut

  • Home
  • Topics
    • Notes
    • Tutorial
    • Bug fixing
    • Extension
    • Server
  • Q&A
  • Privacy Policy
  • About

django-models

Django auto_now and auto_now_add

August 19, 2022 by Magenaut

For Django 1.1.

Categories Python, Q&A Tags datetime, django, django-admin, django-models, python Leave a comment

Can “list_display” in a Django ModelAdmin display attributes of ForeignKey fields?

August 19, 2022 by Magenaut

I have a Person model that has a foreign key relationship to Book, which has a number of fields, but I’m most concerned about author (a standard CharField).

Categories Python, Q&A Tags django, django-admin, django-models, modeladmin, python Leave a comment

Programmatically saving image to Django ImageField

August 19, 2022 by Magenaut

Ok, I’ve tried about near everything and I cannot get this to work.

Categories Python, Q&A Tags django, django-models, python Leave a comment

Django FileField with upload_to determined at runtime

August 19, 2022 by Magenaut

I’m trying to set up my uploads so that if user joe uploads a file it goes to MEDIA_ROOT/joe as opposed to having everyone’s files go to MEDIA_ROOT. The problem is I don’t know how to define this in the model. Here is how it currently looks:

Categories Python, Q&A Tags django, django-models, python Leave a comment

How to pull a random record using Django’s ORM?

August 19, 2022 by Magenaut

I have a model that represents paintings I present on my site. On the main webpage I’d like to show some of them: newest, one that was not visited for most time, most popular one and a random one.

Categories Python, Q&A Tags django, django-models, python Leave a comment

Django – No such table: main.auth_user__old

August 19, 2022 by Magenaut

I was following the first app tutorial from the official Django docs and got this error when trying to save some changes made through the admin page. I did some research on it, but the possible solutions I was able to find, such as migrating the db, simply won’t work. Just let me know if you want to see some specific part of my code.

Categories Python, Q&A Tags django, django-models, python, python-3.x Leave a comment

In Django, how does one filter a QuerySet with dynamic field lookups?

August 18, 2022 by Magenaut

Given a class:

Categories Python, Q&A Tags django, django-models, python Leave a comment

Django – how to create a file and save it to a model’s FileField?

August 18, 2022 by Magenaut

Here’s my model. What I want to do is generate a new file and overwrite the existing one whenever a model instance is saved:

Categories Python, Q&A Tags django, django-models, python Leave a comment

How do I clone a Django model instance object and save it to the database?

August 18, 2022 by Magenaut

Foo.objects.get(pk="foo") <Foo: test> In the database, I want to add another object which is a copy of the object above. Suppose my table has one row. I want to insert the first row object into another row with a different primary key. How can I do that? Answers: Thank you for visiting the Q&A section … Read more

Categories Python, Q&A Tags django, django-models, python Leave a comment

Django Aggregation: Summation of Multiplication of two fields

August 17, 2022 by Magenaut

I have a model something like this:

Categories Python, Q&A Tags django, django-models, django-orm, django-queryset, python Leave a comment
Older posts
Newer posts
← Previous Page1 Page2 Page3 … Page6 Next →
  1. michealSmith07 on Is there a way to dynamically refresh the less command?August 21, 2022

    That is a very nice post. I like this post.

  2. anonymous on Fix libwacom9 dependency issue when upgrade DebianJune 27, 2022

    saved my day!! Thanks for the help…

  3. sreedhar on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    Thanks its working

  4. saintnick on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    remove libwacom2 worked for me as well

  5. ranafoul on Fix libwacom9 dependency issue when upgrade DebianApril 22, 2022

    apt remove libwacom2 helped on kali 2022.01. gr8

.net ajax asp.net asp.net-core asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-web-api bash c# command-line css custom-post-types custom-taxonomy dataframe dictionary django entity-framework functions gridview html iis javascript jquery json linux list matplotlib numpy pandas php plugin-development plugins posts python python-2.7 python-3.x security shell shell-script sql string vb.net webforms wp-query

© 2026 Magenaut • Built with GeneratePress