Changes between Version 88 and Version 89 of IrcFAQ


Ignore:
Timestamp:
Dec 11, 2008, 8:28:53 PM (16 years ago)
Author:
Paul Bissex
Comment:

Cleaned up some old questions and pre-1.0 material

Legend:

Unmodified
Added
Removed
Modified
  • IrcFAQ

    v88 v89  
    5858
    5959
    60 = Learning Django = #Learning
    61 
    62 == Should I read the documentation on the djangoproject.com website, or djangobook.com? == #WhichDocs
    63 
    64 Start with the [http://www.djangoproject.com/documentation/ documentation] here, and then have a look at the book if you're interested; the documentation on djangoproject.com includes the official tutorial, and a number of comprehensive references which aren't currently available in the book.
    65 
    66 == What's the difference between {{{null=True}}} and {{{blank=True}}} in models? == #NullVsBlank
    67 
    68 `null=True` means that the database will accept a `NULL` value for that field; `blank=True` means that Django's validation system won't complain about a missing value. If you use `blank=True` but ''not'' `null=True` you will need to have your code fill in a value before storage in the database -- specifying a default on a field, or putting something in the model's `save` method to generate a value are two good ways to handle this, and can be extremely useful when you want to calculate one field's value based on others.
    69 
    70 == Which runs faster, X or Y? == #WhichIsFaster
    71 
    72 This is a tempting question to ask in hopes of getting a quick answer on the "best" way to do something. Unfortunately, the answer is generally "profile your app and see". Performance tuning always starts with a baseline. If you haven't measured current performance to get a baseline, you aren't in a position to do much with the answer to the question anyway.
    73 
    74 You can learn more about Python's handy profiling tools in the [http://docs.python.org/lib/profile.html Python documentation].
    75 
    76 
    77 
    7860= Troubleshooting =
    7961
     
    9476== I'm using the development version (via Subversion) and when I ran "svn up" a bunch of stuff broke! == #SvnUp
    9577
    96 Don't use the development version of Django unless you also follow the BackwardsIncompatibleChanges and possibly the [http://code.djangoproject.com/timeline timeline] as well. That way you can see what has changed *before* you update. 
     78If you use the development version of Django, follow the BackwardsIncompatibleChanges and the [http://code.djangoproject.com/timeline timeline], so you can see what has changed *before* you update. 
    9779
    9880That way, changes like [http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#Auto-escapingintemplates auto-escaping of HTML in templates] won't catch you by surprise.
    99 
    100 Also, when reading the documentation, keep a special eye out for the "New In Development Version" sections.
    101 
    102 == My app and/or models are not showing up on the home page of the admin == #AppNotInAdmin
    103 
    104  * Is the app listed in {{{INSTALLED_APPS}}}?
    105  * Is your models.py free of syntax errors?
    106  * Do you have an "Admin" inner class in your model?
    107  * Have you tried restarting the server (this includes the dev server)?
    10881
    10982== My media/static files (CSS, images, etc.) aren't showing up. == #MediaTroubles
     
    131104
    132105
    133 == I have a `DateField` or `DateTimeField` with a default value of `now()`, but it's not working! ==
    134 
    135 What you've probably done is something like this:
    136 
    137 {{{
    138 some_date_field = models.DateTimeField(default=datetime.datetime.now())
    139 }}}
    140 
    141 When you do that you're immediately calling `datetime.datetime.now` and passing its return value -- ''at the moment the class is defined'' -- to be the default, which means it will not change during the life of a server process. What you want to do instead is this:
    142 
    143 {{{
    144 some_date_field = models.DateTimeField(default=datetime.datetime.now)
    145 }}}
    146 
    147 Note that there are no parentheses on `datetime.datetime.now` in this version, so you're passing ''the function itself'' to be the default. When Django receives a function as a default value for a model field, it will call the function each time a new object is saved, and that will correctly generate the current date/time for each object.
    148 
    149 
    150106= How to do Stuff =
    151107
    152108== How do I create a subclass of an existing model? == #ModelInheritance
    153109
    154 Model inheritance (aka model subclassing) is available in Django trunk as of r7477.
    155 
    156 If you're using it, make sure you've [http://www.djangoproject.com/documentation/model-api/#model-inheritance read the documentation] and understand the difference between '''abstract base class''' and '''multi-table''' inheritance options. The latter can be confusing to newcomers because an instance of a parent class will also contain, on an attribute named after a child class, that same object represented as an instance of the child class. Got that?
     110If you're using model inheritance (aka model subclassing), make sure you've [http://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance read the documentation] and understand the difference between the '''abstract base class''' and '''multi-table''' inheritance options. The latter can be confusing to newcomers because an instance of a parent class will also contain, on an attribute named after a child class, that same object represented as an instance of the child class. Got that?
    157111
    158112An established mechanism for adding additional information to Django `User` objects without subclassing is known as  "profiles"; you can [http://www.djangobook.com/en/1.0/chapter12/#s-profiles read about it in the Definitive Guide].
     
    169123
    170124The admin interface is designed for use by trusted site staff, not by any user -- if you don't trust a user with the level of access the admin application provides, you'll need to provide non-admin views for the actions you'd like to allow them to take.
    171 
    172 == How do I make extensive changes in the admin interface? == #ExtensiveChangesAdmin
    173 
    174 At the moment it's probably best not to; the admin app is fairly specialized and doesn't have a lot of places to customize behavior, so you'll usually end up writing less code by just rolling your own set of views. The [http://code.djangoproject.com/wiki/NewformsAdminBranch newforms-admin branch], however, is significantly changing the admin app's interfaces to make customization much simpler and more flexible.
    175 
    176 For less extensive changes, also see the documentation in [http://www.djangobook.com/en/1.0/chapter17/ The Definitive Guide to Django].
    177125
    178126== I want to have some code run when the server/application starts. How do I do that? == #ServerStartup
     
    210158= Resources, Tools, and Code = #Resources
    211159
     160== Which runs faster, X or Y? == #WhichIsFaster
     161
     162This is a tempting question to ask in hopes of getting a quick answer on the "best" way to do something. Unfortunately, the answer is generally "profile your app and see". Performance tuning always starts with a baseline. If you haven't measured current performance to get a baseline, you aren't in a position to do much with the answer to the question anyway.
     163
     164You can learn more about Python's handy profiling tools in the [http://docs.python.org/lib/profile.html Python documentation].
     165
    212166== What editor is best for Django? == #WhichEditor
    213167
    214168[wiki:UsingVimWithDjango Vim]. No, wait, [wiki:Emacs Emacs]. A lot of people seem to like TextMate, too. The best editor is the editor ''you'' prefer.
    215 
    216 == Is there a free CMS available for Django? == #CMS
    217 
    218 At this point there is nothing well-established (like Plone, for instance). In practice, people mean so many different things by "CMS" that it may be hard to get a straight answer. This question is often asked by newcomers; one recommendation is to learn a bit of Django and see just how easy it is to make a site that does what you want. If you're in a big rush, there's always Ellington:  http://www.ellingtoncms.com/
    219 
    220 There is also a new (April '08) project called [http://pinax.hotcluboffrance.com/ Pinax] that combines a number of open-source Django apps into an integrated starting point for websites that need authentication and membership features.
    221169
    222170== Where can I find example code and/or reusable apps? == #ShowMeTheCode
     
    226174 * http://www.djangosites.org/with-source/
    227175 * http://djangoplugables.com/
    228  * http://code.google.com/p/django-hotclub/
     176 * http://pinaxproject.com/
    229177 * http://code.google.com/hosting/search?q=label:django
    230178 * http://github.com/search?q=django
Back to Top