django – get user logged into test client

The test client is request-agnostic. It doesn’t inherently hold information about what users are logged in. (Neither does your actual webserver or the Django dev server, either, for obvious reasons, and those same reasons apply here). login is simply a convenience method on the test client to essentially mimic a POST to /login/ with the … Read more

Django: Admin: changing the widget of the field in Admin

UPDATE 1: Code that gets me done with 1) (don’t forget tot pass CHOICES to the BooleanField in the model) from main.models import TagCat from django.contrib import admin from django import forms class MyTagCatAdminForm(forms.ModelForm): class Meta: model = TagCat widgets = { ‘by_admin’: forms.RadioSelect } fields=”__all__” # required for Django 3.x class TagCatAdmin(admin.ModelAdmin): form = … Read more

Django Forms with ReactJS

First, i think you need to check related React documentation about forms with multiple inputs. It gives you base idea about how things should be structured in React side. About fetching data from server, you can try something like this in componentDidMount: componentDidMount() { // Assuming you are using jQuery, // if not, try fetch(). … Read more

Foreign keys in django admin list display

I was looking for a solution to the same problem and ran across this question… ended up solving it myself. The OP might not be interested anymore but this could still be useful to someone. from functools import partial from django.forms import MediaDefiningClass class ModelAdminWithForeignKeyLinksMetaclass(MediaDefiningClass): def __getattr__(cls, name): def foreign_key_link(instance, field): target = getattr(instance, field) … Read more