def setUp(self): b = Band(name='Aerosmith', bio='', rank=3) b.save() self.b = b s1 = Song(band=b, name='Pink', duration=235) s1.save() s2 = Song(band=b, name='Dude (Looks Like a Lady)', duration=264) s2.save() s3 = Song(band=b, name='Jaded', duration=214) s3.save()
def setUp(self): b = Band(name='Aerosmith', bio='', rank=3) b.save() self.b = b s1 = Song(band=b, name='Pink', duration=235) s1.save() s2 = Song(band=b, name='Dude (Looks Like a Lady)', duration=264) s2.save() s3 = Song(band=b, name='Jaded', duration=214) s3.save()
def testBandOncePerNight(self): """ TODO """ band = Band(name="Test band 1") band.save() BandByNight(night=self.night, band=band, price=Decimal("10.00")).save() with self.assertRaises(IntegrityError): BandByNight(night=self.night, band=band, price=Decimal("10.00")).save()
def test_queryset_override(self): # If we need to override the queryset of a ModelChoiceField in our custom form # make sure that RelatedFieldWidgetWrapper doesn't mess that up. band2 = Band(name="The Beatles", bio="", sign_date=date(1962, 1, 1)) band2.save() class ConcertAdmin(ModelAdmin): pass ma = ConcertAdmin(Concert, self.site) form = ma.get_form(request)() self.assertEqual( str(form["main_band"]), '<select name="main_band" id="id_main_band">\n' '<option value="" selected="selected">---------</option>\n' '<option value="%d">The Beatles</option>\n' '<option value="%d">The Doors</option>\n' "</select>" % (band2.id, self.band.id), ) class AdminConcertForm(forms.ModelForm): class Meta: model = Concert def __init__(self, *args, **kwargs): super(AdminConcertForm, self).__init__(*args, **kwargs) self.fields["main_band"].queryset = Band.objects.filter(name="The Doors") class ConcertAdmin(ModelAdmin): form = AdminConcertForm ma = ConcertAdmin(Concert, self.site) form = ma.get_form(request)() self.assertEqual( str(form["main_band"]), '<select name="main_band" id="id_main_band">\n' '<option value="" selected="selected">---------</option>\n' '<option value="%d">The Doors</option>\n' "</select>" % self.band.id, )
def setUp(self): """ TODO """ self.stadium = Stadium(name="test stadium") self.stadium.save() self.festival = Festival(stadium=self.stadium, name="test festival", base_price=Decimal("10.00")) self.festival.save() self.night = Night(festival=self.festival, datetime=datetime.now()) self.night.save() for i in range(2): band = Band(name="Test band %d" % i) band.save() BandByNight(night=self.night, band=band, price=Decimal("10.00")).save()
def test_queryset_override(self): # If we need to override the queryset of a ModelChoiceField in our custom form # make sure that RelatedFieldWidgetWrapper doesn't mess that up. band2 = Band(name='The Beatles', bio='', sign_date=date(1962, 1, 1)) band2.save() class ConcertAdmin(ModelAdmin): pass ma = ConcertAdmin(Concert, self.site) form = ma.get_form(request)() self.assertEqual( str(form["main_band"]), '<select name="main_band" id="id_main_band">\n' '<option value="" selected="selected">---------</option>\n' '<option value="%d">The Beatles</option>\n' '<option value="%d">The Doors</option>\n' '</select>' % (band2.id, self.band.id)) class AdminConcertForm(forms.ModelForm): class Meta: model = Concert def __init__(self, *args, **kwargs): super(AdminConcertForm, self).__init__(*args, **kwargs) self.fields["main_band"].queryset = Band.objects.filter( name='The Doors') class ConcertAdmin(ModelAdmin): form = AdminConcertForm ma = ConcertAdmin(Concert, self.site) form = ma.get_form(request)() self.assertEqual( str(form["main_band"]), '<select name="main_band" id="id_main_band">\n' '<option value="" selected="selected">---------</option>\n' '<option value="%d">The Doors</option>\n' '</select>' % self.band.id)
def setUp(self): b1 = Band(name='Aerosmith', bio='', rank=3) b1.save() b2 = Band(name='Radiohead', bio='', rank=1) b2.save() b3 = Band(name='Van Halen', bio='', rank=2) b3.save()
def setUp(self): b1 = Band(name='Aerosmith', bio='', rank=3) b1.save() b2 = Band(name='Radiohead', bio='', rank=1) b2.save() b3 = Band(name='Van Halen', bio='', rank=2) b3.save()
def setUp(self): self.request_factory = RequestFactory() b1 = Band(name='Aerosmith', bio='', rank=3) b1.save() b2 = Band(name='Radiohead', bio='', rank=1) b2.save() b3 = Band(name='Van Halen', bio='', rank=2) b3.save()
def setUp(self): self.request_factory = RequestFactory() b1 = Band(name='Aerosmith', bio='', rank=3) b1.save() b2 = Band(name='Radiohead', bio='', rank=1) b2.save() b3 = Band(name='Van Halen', bio='', rank=2) b3.save()
def new_band(request): if request.method == 'POST': #create the band bandName = request.POST.get('bandName', False) newBand = Band(name=bandName, owner=request.user) newBand.save() newBandId = newBand.id #add user as member newMemberName = request.user.first_name + " " + request.user.last_name newMemberPhone = request.POST.get('phoneNumber', False) newMemberRole = request.POST.get('role', False) newMember = Member( band=newBand, name=newMemberName, userName=request.user, role=newMemberRole, phone=newMemberPhone, email=request.user.email, status=Member.MANAGER ) newMember.save() return HttpResponseRedirect('/app/' + str(newBandId)) return HttpResponseRedirect('/')