SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    Web Design Addict
    Join Date
    Mar 2004
    Posts
    2,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing widths of Django Admin forms

    Hi,

    Sorry if this is the wrong place to post this as I don't see a Django specific area.

    I'm new to Python and Django. Spent a few weeks getting to know Python; went through "Python in a Day" and about half of "Python the Hard Way" before I dove into Django. I'm understanding a lot of things, but still plenty that is over my head.

    Currently I've got a Blog app set up and my models.py completed. Problem is, the form fields are all about 200px wide. I'd like to customize the fields with custom widths and cols/rows for textareas.

    Here's my current admin.py file:

    Code Python:
    from django.contrib import admin
    from blog.models import Post
    from django import forms
     
    class PostAdminForm(forms.ModelForm):
    	title = forms.CharField(widget=forms.TextInput(attrs={'size':100}))
     
    class PostAdmin(admin.ModelAdmin):
    	list_display = ('title', 'status', 'pub_date', 'image', 'summary')
    	list_filter = ['pub_date', 'status']
    	search_fields = ['title', 'summary', 'body']
    	date_hierarchy = 'pub_date'
     
    admin.site.register(Post, PostAdmin)

    You can see where I've tried to set a custom size for the title field. I get no errors or anything with this code yet the title field doesn't change in size. What am I missing?

    I also found this bit of code which was from the same thread as I found the above. The poster indicated that it was "better" in some way but I can't seem to make it work either:

    Code Python:
    def get_form(self, request, obj=None): 
    	form = super(EventAdmin,self).get_form(request, obj=None) 
    	name = forms.CharField(widget=forms.TextInput(attrs={'size': 
    	100, 'max_length':200}),required=True,) 
    	form.base_fields['name']=name 
    	return form
    Last edited by Mittineague; Sep 16, 2013 at 21:54. Reason: reformatting bbcode tags
    Deron Sizemore
    ----------
    My Sites: LogoGala | Golf Ledger (coming soon)
    Twitter: Deron Sizemore


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •