daily pastebin goal
87%
SHARE
TWEET

Untitled

a guest Aug 19th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.contrib.auth.models import User
  2.  
  3. class ModelOne1(models.Model):
  4.     VALUE1 = 'value1'
  5.     VALUE2 = 'value2'
  6.     DAYS = (
  7.         (VALUE1, 'value1'),
  8.         (VALUE2, 'value2'),
  9.     )
  10.     user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
  11.     days = models.CharField(max_length=7, choices=DAYS, default=VALUE1)
  12.  
  13.     def is_upperclass(self):
  14.         return self.days in (self.VALUE1, self.VALUE2)
  15.  
  16.  
  17. class ModelTwo2(models.Model):
  18.     VALUE1 = 'value1'
  19.     VALUE2 = 'value2'
  20.     DAYS = (
  21.         (VALUE1, 'value1'),
  22.         (VALUE2, 'value2'),
  23.     )
  24.     user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
  25.     days = models.CharField(max_length=7, choices=DAYS, default=VALUE1)
  26.  
  27.     def is_upperclass(self):
  28.         return self.days in (self.VALUE1, self.VALUE2)
  29.    
  30. class Allmodels(models.Model):
  31.     model1 = models.ForeignKey(ModelOne1, on_delete=models.CASCADE, null=True)
  32.     model2 = models.ForeignKey(ModelTwo2, on_delete=models.CASCADE, null=True)
  33.    
  34. from django import forms
  35. from .models import ModelOne1, ModelTwo2
  36. from django.contrib.auth.models import User
  37.  
  38. class FormOfModel1(forms.ModelForm):
  39.     class Meta:
  40.         model  = ModelOne1
  41.         fields = ['days']
  42.         widgets = {
  43.             'user': forms.ModelChoiceField(queryset=User.objects.all()),
  44.             'days': forms.Select(attrs={'class':'x'}),
  45.         }
  46.  
  47.  
  48.  class FormOfModel2(forms.ModelForm):
  49.      class Meta:
  50.          model  = ModelTwo2
  51.          fields = ['days']
  52.          widgets = {
  53.              'user': forms.ModelChoiceField(queryset=User.objects.all()),
  54.              'days': forms.Select(attrs={'class':'x'}),
  55.          }
  56.    
  57. class AllView(ListView):
  58.      model = Allmodels
  59.      template_name = 'x/allview_list.html'
  60.  
  61.      def get_queryset(self):
  62.          return Allmodels.objects.filter(user=self.request.user)
  63.    
  64. Allmodels.objects.filter(user=self.request.user)
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