Changes between Version 39 and Version 40 of NewbieMistakes


Ignore:
Timestamp:
Feb 21, 2011, 12:57:24 AM (13 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NewbieMistakes

    v39 v40  
    332332
    333333Ensure they have different values - e.g. ADMIN_MEDIA_PREFIX = 'admin-media' and MEDIA_URL = '/media'
     334
     335
     336== Default value and Callables ==
     337
     338==== Symptom ====
     339
     340You call a method to set a default value, such as random.randint(), but the value is the same for every new instance of your object.
     341
     342==== Probable cause ====
     343
     344Each new instance doesn't call random.randint()
     345
     346==== Solution ====
     347
     348Prepend "lambda:" like
     349{{{
     350MyRandNum = models.CharField(max_length=4, default=lambda:random.randint(1000,9999))
     351}}}
     352
Back to Top