class OrganisationAdmin(admin.ModelAdmin): formfield_overrides = { AddressField: { 'widget': AddressWidget(attrs={'style': 'width: 300px;'}) } } inlines = (OrganisationRegistrationInLine, )
class CarpetaFamiliarAdmin(admin.ModelAdmin): exclude = [] formfield_overrides = { AddressField: { "widget": AddressWidget(attrs={"style": "width: 300px;"}) } }
class CarpetaFamiliarAdmin(admin.ModelAdmin): exclude = [] formfield_overrides = { AddressField: { 'widget': AddressWidget(attrs={'style': 'width: 300px;'}) } }
class RestaurantAdmin(admin.ModelAdmin): list_display = ('id', 'name', 'address', 'outlet_type', 'cuisine_type', 'affordability', 'vegan_friendly', 'halal') formfield_overrides = { AddressField: { 'widget': AddressWidget(attrs={'style': 'width: 300px;'}) } }
class PersonAdmin(admin.ModelAdmin): list_display = ( 'id', 'address', ) formfield_overrides = { AddressField: { 'widget': AddressWidget(attrs={'style': 'width: 300px;'}) } }
class PersonAdmin(admin.ModelAdmin): list_display = ( "id", "first_name", "address", ) formfield_overrides = { AddressField: { "widget": AddressWidget(attrs={"style": "width: 300px;"}) } }
class CustomUserAdmin(UserAdmin): formfield_overrides = { AddressField: { 'widget': AddressWidget(attrs={'style': 'width: 300px;'}) } } inlines = (ProfileInline, ) def get_inline_instances(self, request, obj=None): if not obj: return list() return super(CustomUserAdmin, self).get_inline_instances(request, obj) class Media: js = ('js/jquery-3.2.1.min.js')
class BuyerCreationForm(forms.ModelForm): """A form for creating new_profile users. Includes all the required fields, plus a repeated password.""" address = AddressField( label='Адрес', widget=AddressWidget(attrs={'placeholder': 'введите свой адрес'}), help_text='улица Макарова, 24, Ровно, Ровенская область, Украина') password1 = forms.CharField( label=_('Password'), widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': _('введите пароль') })) password2 = forms.CharField( label=_('Password confirmation'), widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': _('повторите пароль') })) class Meta: model = BuyerUser fields = ('email', 'first_name', 'last_name', 'date_of_birth', 'sex', 'phone_number') def clean_password1(self): password1 = self.cleaned_data.get("password1") valid_password = validate_password(password1) if valid_password is not None: raise valid_password.ValidationError() return password1 def clean_password2(self): # Check that the two password entries match password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError("Пароли не совпадают") return password2 def save(self, commit=True): # Save the provided password in hashed format user = super(BuyerCreationForm, self).save(commit=False) user.set_password(self.cleaned_data["password1"]) if commit: user.save() return user
class LocationAdmin(admin.ModelAdmin): '''Admin View for Location''' list_display = ( 'address', 'location_type', ) list_filter = ( 'location_type', ) search_fields = ( 'address', 'location_type', ) fieldsets = ( ( "", { 'classes': ( 'wide', ), 'fields': ( 'address', 'location_type', ) } ), ) formfield_overrides = { AddressField: { 'widget': AddressWidget( attrs={ 'style': 'width: 400px;' } ) } }
def test_attributes_set_correctly(self): wid = AddressWidget(attrs={'size': '150'}) self.assertEqual(wid.attrs['size'], '150') html = wid.render('test', None) self.assertNotEqual(html.find('size="150"'), -1)
def test_attributes_set_correctly(self): wid = AddressWidget(attrs={"size": "150"}) self.assertEqual(wid.attrs["size"], "150") html = wid.render("test", None) self.assertNotEqual(html.find('size="150"'), -1)
class ApplicationAdmin(admin.ModelAdmin): form = ApplicationAdminForm readonly_fields = [ "datetime_submitted", "user", "is_adult", "gender", "race", "major", "school", "classification", "grad_year", "num_hackathons_attended", "technology_experience", "extra_links", "address", "question1", "question2", "question3", "notes", "is_a_walk_in", ] list_filter = ( ("school", RelatedOnlyFieldListFilter), ("status", ChoiceDropdownFilter), ("classification", ChoiceDropdownFilter), ("gender", ChoiceDropdownFilter), ("grad_year", ChoiceDropdownFilter), ("num_hackathons_attended", ChoiceDropdownFilter), ("technology_experience", ChoiceDropdownFilter), ("shirt_size", ChoiceDropdownFilter), ("datetime_submitted", DateRangeFilter), RaceFilter, ) list_display = ( "first_name", "last_name", "school", "user_email", "datetime_submitted", "classification", "grad_year", "status", ) fieldsets = [ ("Related Objects", {"fields": ["user"]}), ("Status", {"fields": ["status"]}), ( "Personal Information", { "fields": [ "first_name", "last_name", "extra_links", "question1", "question2", "question3", "resume", ] }, ), ( "Demographic Information", { "fields": [ "school", "school_other", "major", "classification", "gender", "gender_other", "race", "race_other", "grad_year", "num_hackathons_attended", "technology_experience", ] }, ), ( "Logistical Information", { "fields": [ "shirt_size", "additional_accommodations", "address", ] }, ), ("Confirmation Deadline", {"fields": ["confirmation_deadline"]}), ("Miscellaneous", {"fields": ["notes"]}), ] formfield_overrides = { AddressField: {"widget": AddressWidget(attrs={"style": "width: 300px;"})} } list_per_page = 2000 approve.short_description = "Approve Selected Applications" reject.short_description = "Reject Selected Applications" export_application_emails.short_description = ( "Export Emails for Selected Applications" ) resend_confirmation.short_description = ( "Resend Confirmation to Selected Applications" ) actions = [approve, reject, export_application_emails, resend_confirmation] def has_add_permission(self, request): return True def has_change_permission(self, request, obj=None): return True @staticmethod def user_email(obj: Application) -> str: return obj.user.email @staticmethod def is_a_walk_in(obj: Application) -> bool: return obj.wave.is_walk_in_wave
class ExampleAdmin(admin.ModelAdmin): formfield_overrides = { AddressField: { 'widget': AddressWidget(attrs={'style': 'width: 300px;'}) } }