daily pastebin goal
86%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Defendant(models.Model):
  2.     fullname         = models.CharField(max_length = 100, null = False,)
  3.     fname            = models.CharField(max_length = 100, verbose_name = u'First Name', blank = True, null = True,)
  4.     midname          = models.CharField(max_length = 100, verbose_name = u'Middle Name', blank = True, null = True,)
  5.     lname            = models.CharField(max_length = 50, verbose_name = u'Last Name', null = True, blank = True,)
  6.     marked           = models.CharField(max_length = 50, verbose_name = u'Check box mark', null = True, blank = True,)
  7. class Defendant_Potential(models.Model):
  8.     defendant    = models.ForeignKey('Defendant', related_name = "Defendant_defendantID",)
  9.     midname      = models.CharField(max_length = 100, blank = True, null = True, default = None)
  10.     address      = models.CharField(max_length = 100, null = False,)
  11.     city         = models.CharField(max_length = 50, null = False,)
  12.     state        = models.CharField(max_length = 5, null = False,)
  13.     zip      = models.CharField(max_length = 50, null = False,)
  14.    
  15. class Defendant_Potential_Individual_Inline(admin.TabularInline):
  16.     model = Defendant_Potential
  17.  
  18.     formset = NoDeleteAdminInlineFormSet
  19.     readonly_fields = ('midname', 'address')
  20.     extra = 0
  21.     template = "admin/cdradmin/defendant/edit_inline/tabular.html"
  22.  
  23. class DefendantAdmin(admin.ModelAdmin):
  24.     list_display = ('fullname', 'fname','midname','lname')
  25.  
  26.     inlines = [Defendant_Potential_Individual_Inline, ]
  27.    
  28. <td><input type="checkbox"  name="defendant_potential_checked" data-defendant_id="{{ inline_admin_form.original.defendant_id }}" value="{{ inline_admin_form.original.id }}"></input></td>
  29.    
  30. class Hive(models.Model):
  31.     name = models.CharField(max_length=100)
  32.     marker = models.BooleanField(default=False)
  33.  
  34.  
  35. class Bee(models.Model):
  36.     hive = models.ForeignKey(Hive)
  37.     name = models.CharField(max_length=100)
  38.    
  39. class BeeForm(forms.ModelForm):
  40.     check = forms.BooleanField(label="check", required=False)
  41.     class Meta:
  42.         model = Bee
  43.  
  44. class BeeInline(admin.TabularInline):
  45.     form = BeeForm
  46.     model = Bee
  47.  
  48. class HiveAdmin(admin.ModelAdmin):
  49.     inlines = (BeeInline,)
  50.     def save_formset(self, request, form, formset, change):
  51.         for bee_form in formset:
  52.             if bee_form.cleaned_data.get('check') == True:
  53.                 form.instance.marker = True
  54.                 form.instance.save()
  55.         super(HiveAdmin, self).save_formset(request, form, formset, change)
  56.  
  57. admin.site.register(Hive, HiveAdmin)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top