On 12-7-2012 15:51, Jaroslav Dobrek wrote:

> Users may create Test objects in order to run their own tests. A test 
> always starts at some date time and it always ends at some date time. Each 
> test has a time which is increased until it equals the end time. When a 
> user creates a new test (and before he uses it) the field time should have 
> the same value as the field start_time.

(Assuming the time field should be stored in the database)

Simplest, but specific for temporal fields:
class Test(models.Model) :
        start_time = models.DateTimeField(auto_now_add=True)
        end_time = models.DateTimeField(auto_now_add=True)
        time = models.DateTimeField(auto_now_add=True)

Generally working:
class Test(models.Model) :
        first = models.CharField(max_length=10, default='first')
        second = models.CharField(max_length=10)

        def __init__(self, *args, **kwargs) :
                first = kwargs.get('first', False)
                if not first :
                        first = self.__class__.first.default
                second = first
                if not kwargs.get('second', False) :
                        kwargs['second'] = second
                super(Test, self).__init__(*args, **kwargs)

For the admin, see
<https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.prepopulated_fields>
for an alternate solution.
-- 
Melvyn Sopacua


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to