Search Results

Search found 5 results on 1 pages for 'slypete'.

Page 1/1 | 1 

  • Why don't these class attributes register?

    - by slypete
    I have a factory method that generates django form classes like so: def get_indicator_form(indicator, patient): class IndicatorForm(forms.Form): #These don't work! indicator_id = forms.IntegerField(initial=indicator.id, widget=forms.HiddenInput()) patient_id = forms.IntegerField(initial=patient.id, widget=forms.HiddenInput()) def __init__(self, *args, **kwargs): forms.Form.__init__(self, *args, **kwargs) self.indicator = indicator self.patient = patient #These do! setattr(IndicatorForm, 'indicator_id', forms.IntegerField(initial=indicator.id, widget=forms.HiddenInput())) setattr(IndicatorForm, 'patient_id', forms.IntegerField(initial=patient.id, widget=forms.HiddenInput())) for field in indicator.indicatorfield_set.all(): setattr(IndicatorForm, field.name, copy(field.get_field_type())) return type('IndicatorForm', (forms.Form,), dict(IndicatorForm.__dict__)) I'm trying to understand why the top form field declarations don't work, but the setattr method below does work. I'm fairly new to python, so I suspect it's some language feature that I'm misunderstanding. Can you help me understand why the field declarations at the top of the class don't add the fields to the class? In a possibly related note, when these classes are instantiated, instance.media returns nothing even though some fields have widgets with associated media. Thanks, Pete

    Read the article

  • Alternate datasource for django model?

    - by slypete
    I'm trying to seamlessly integrate some legacy data into a django application. I would like to know if it's possible to use an alternate datasource for a django model. For example, can I contact a server to populate a list of a model? The server would not be SQL based at all. Instead it uses some proprietary tcp based protocol. Copying the data is not an option, as the legacy application will continue to be used for some time. Would a custom manager allow me to do this? This model should behave just like any other django model. It should even pluggable to the admin interface. What do you think? Thanks, Pete

    Read the article

  • Sorting and indexing into a list in a Django template?

    - by slypete
    How can you perform complex sorting on an object before passing it to the template? For example, here is my view: @login_required def overview(request): physicians = PhysicianGroup.objects.get(pk=physician_group).physicians for physician in physicians.all(): physician.service_patients.order_by('bed__room__unit', 'bed__room__order', 'bed__order') return render_to_response('hospitalists/overview.html', RequestContext(request, {'physicians': physicians,})) The physicians object is not ordered correctly in the template. Why not? Additionally, how do you index into a list inside the template? For example, (this doesn't work): {% for note_type in note_types %} <div><h3>{{ note_type }}</h3> {% for notes in note_sets.index(parent.forloop.counter0) %} #only want to display the notes of this note_type! {% for note in notes %} <p>{{ note }}</p> {% endfor %} {% endfor %} </div> {% endfor %}

    Read the article

  • How do I use django settings in my logging.ini file?

    - by slypete
    I have a BASE_DIR setting in my settings.py file: BASE_DIR = os.path.dirname(os.path.abspath(__file__)) I need to use this variable in my logging.ini file to setup my file handler paths. The initialization of logging happens in the same file, the settings.py file, below my BASE_DIR variable: LOG_INIT_DONE=False if not LOG_INIT_DONE: logging.config.fileConfig(LOGGING_INI) LOG_INIT_DONE=True Thanks, Pete

    Read the article

  • Storing GenericForeignKey content_type in another model?

    - by slypete
    I have a typical definition/instance situation in my data modeling. I'm trying to store the content_type of a GenericForeignKey in another model (the definition model) like so: class IndicatorFieldInstance(models.Model): definition = models.ForeignKey(IndicatorField) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey(definition.content_type, 'object_id') indicator_instance = models.ForeignKey(IndicatorInstance) I've also tried it like this: content_object = generic.GenericForeignKey('definition__content_type', 'object_id') Neither of these methods seem to work. Is it possible to achieve this? For reference, here's the definition model: class IndicatorField(models.Model): name = models.CharField(max_length='255') content_type = models.ForeignKey(ContentType) indicator = models.ForeignKey(Indicator) Thanks, Pete

    Read the article

1