Hi,

In my model I have the field:


    created_by = meta.ForeignKey(
        User,
        verbose_name='created by',
        editable=False,
        blank=True,
        null=True
    )


and the module method below to create a "validated" object:

    def _module_create(address, prefix, description, maintainer,
customer, created_by):
        from django.utils.datastructures import MultiValueDict
        from django.models.ip import ipsupernetworks

        data = MultiValueDict({
            'address': [address],
            'prefix': [prefix],
            'description': [description],
            'maintainer': [maintainer.id],
            'customer': [customer.id],
            'created_by': [created_by.id],
            'changed_by': [created_by.id],
        })
        manipulator = ipsupernetworks.AddManipulator()
        errors = manipulator.get_validation_errors(data)
        if errors:
            return None, errors
        else:
            manipulator.do_html2python(data)
            obj = manipulator.save(data)
            return obj, errors

But when I call obj.get_created_by() on a newly created object i get
'None'. When I remove "editable=False" from the field definition it
works.

is this how it is meant to behave? I do not want to have this field in
the admin but be still able to set it in the method above. Is there
another way of doing it? I know i can call mymodule.MyModel(...) but
this doesn't validate the arguments as far as I can tell.

regards

matthew

Reply via email to