开发者

Django: Adjacents Fields

开发者 https://www.devze.com 2022-12-17 14:42 出处:网络
I made a simple project named \"employee\" with an \"info\" app. When I add a new employee the fields comes one below the other, like this:

I made a simple project named "employee" with an "info" app.

When I add a new employee the fields comes one below the other, like this:

name:____

eno:____

phone开发者_Go百科1:____

phone2:____

How can I get the output to be like this:

name:____

eno:____

phone1:________________ phone2:____________


Since you say "when I add a new employee," I assume you're talking about in the Django admin?

In that case, you need to set the "fieldsets" attribute of your ModelAdmin subclass, and wrap those two fields inside a tuple. Something like this in your admin.py:

class EmployeeAdmin(admin.ModelAdmin):
    fieldsets = ((None, {'fields': ('name', 'eno', ('phone1', 'phone2'))}),)


In your template set up the boxes for the fields however you like (tables, CSS, etc.), then use {{ form.fieldname }} to display only the HTML for the form input.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号