假设我有以下代码:
文件模型.py:
from django.db import models
from django.contrib.auth.models import User
class MyClass(models.Model):
username = models.ForeignKey(User, blank=True, null=True)
my_field = models.CharField(max_length=200, default="sample_field")
File views.py
from django.forms.models import inlineformset_factory
from django.contrib.auth.models import User
from myapp.models import MyClass
@login_required
def index(request):
username = User.objects.get(username=request.user.username)
MyClassFormSet = inlineformset_factory(User, MyClass, can_delete=False, extra=5)
formset = MyClassFormSet(instance=username)
...
在此处将 CSS 类添加到 my_field 字段的最简单方法是什么?(我在 SO 上看到了一些关于表单的答案,但没有看到模型的答案)。