[Solved]-Django admin inline with custom queryset

11👍 ✅ The old answer doesn’t work anymore for current Django 2.2 or 3 because self.queryset get ignored Current solution is to override the get_queryset: from django.forms.models import BaseInlineFormSet class ChildInlineFormSet(BaseInlineFormSet): def get_queryset(self): qs = super(ChildInlineFormSet, self).get_queryset() return qs.filter(<custom query filters>) class ChildInline(admin.TabularInline): model = Child formset = ChildInlineFormSet extra = 0 👤Linh Nguyen What … Read more

[Solved]-What type files should be put into .gitignore file in Django project

25👍 ✅ There is a popular web service called Gitignore.io that help developers generate gitignore files for popular framework and languages. You can see the Django one here. *.log *.pot *.pyc __pycache__/ local_settings.py db.sqlite3 media On top of that I would also recommend you to ignore things environment items such as virtualenv, or .env files … Read more

[Solved]-Django CSRF Failed: CSRF token missing or incorrect

22👍 Solution You need to set the X-CSRFToken in the Header settings of Insomnia (https://support.insomnia.rest/article/49-cookies ). Go to Header Settings in Insomnia Add a new entry X-CSRFToken Search vor cookie, click on Request => Cookie Click again on Request => Cookie Type csrftoken into Cookie Name Click Done and try it again. Explanation The CSRF … Read more

[Solved]-ImportError: 'tests' module incorrectly

25👍 Delete the tests.py file automatically generated by Django. That helped me make it work. For more information, see this website. 👤Mark Country/State/City dropdown menus inside the Django admin inline 0👍 To expand on Mark’s answer, especially in case the link bit-rots, the most common reason this happens is a conflict between two potential definitions … Read more

[Solved]-Country/State/City dropdown menus inside the Django admin inline

26👍 ✅ With a little hackery, it’s quite doable. In the following example, County is used instead of State and Municipality instead of City. So, the models are as follows: class County(models.Model): name = models.CharField(_(‘Name’), max_length=100, unique=True) class Municipality(models.Model): county = models.ForeignKey(County, verbose_name=_(‘County’)) name = models.CharField(_(‘Name’), max_length=100) class Location(models.Model): name = models.CharField(max_length=100) county = models.ForeignKey(County, … Read more