Friday, August 30, 2013

Re: Admin: Add new dataset with a pre-selected foreign key?

Take a look at filters in the admin. You might be able to add log entries to recent items using an appropriate ModelAdmin on 'entry_created'

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter

Then use an InlineModelAdmin

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin

You could then select the sample by finding recently added samples, clicking on it, then add the log entry

K



On Friday, August 30, 2013 7:45:14 AM UTC-7, Katja wrote:
Hi,

I have a data model like this:
class Samples(models.Model): 
  sample_id = models.CharField(max_length=128, help_text='Id of the sample')
  entry_created = models.DateTimeField(auto_now_add=True)
  sample_status = models.CharField(choices=SAMPLE_STATUS_CHOICES, max_length=128)
  comments = models.TextField(null=True, blank=True)
  def __unicode__(self):
    return ("%s" % (self.sample_id))

class StatusLog(models.Model):
  sample_id = models.ForeignKey(Samples)
  lsu_proc_id = models.IntegerField()
  orig_lab = models.ForeignKey(OriginatingLab)
  cruise_id = models.ForeignKey(Cruises)
  tier = models.ForeignKey(Tiers)
  orig_tier_tote_nr = models.IntegerField()
  gear_type = models.ForeignKey(GearType)
  orig_number_jars = models.IntegerField()
  all_consumed = models.CharField(max_length=3, choices=YES_NO_CHOICE)
  def __unicode__(self):
    return ("%s %s" %(self.sample_id, self.lsu_proc_id))

....

So first I add a Sample, and later I want to add a status log entry - using the admin interface.
Problem: My list of samples will be LONG (right now roughly 1000 entries, more are coming).

Is there any way that I can call the "add" page (http://MYSERVER/admin/statuslog/statuslog/add/) with the sample already preselected, so I don't have to go through the whole list?

Any ideas?

Thanks!
Katja

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment