<commit_before>from django.contrib import admin
from django.db import models
from django import forms

from adhack.adapp.models import PollOption, Poll

class PollOptionInlineAdmin(admin.TabularInline):
    model = PollOption

class MyWhackyForm(forms.Form):
    name = forms.CharField(max_length=30)

    def __init__(self, data=None, files=None, instance=None, **kwargs):
        self._instance = instance

        initial = kwargs.setdefault('initial', {})
        if instance:
            initial['name'] = instance.name

        super(MyWhackyForm, self).__init__(data, files, **kwargs)

    def save_m2m(self):
        pass

    def save(self, commit=True):
        obj = self._instance or Poll()

        obj.name = self.cleaned_data['name']
        obj.question = 'Do you really think %s is true?' % self.cleaned_data['name']
        if commit:
            obj.save()

        return obj

class PollAdmin(admin.ModelAdmin):
    inlines = [PollOptionInlineAdmin]
    list_display = ('name','question', )

    def get_form(self, request, obj=None, **kwargs):
        return MyWhackyForm

admin.site.register(Poll, PollAdmin)
<commit_msg>Extra fields, using fieldsets, Django broke my code<commit_after>from django.contrib import admin
from django.db import models
from django import forms

from adhack.adapp.models import PollOption, Poll

class PollOptionInlineAdmin(admin.TabularInline):
    model = PollOption

class MyWhackyForm(forms.Form):
    subject = forms.CharField(max_length=30)
    adverb = forms.CharField(max_length=30)
    adjective =  forms.CharField(max_length=30)

    def __init__(self, data=None, files=None, instance=None, **kwargs):
        self._instance = instance
        super(MyWhackyForm, self).__init__(data, files, **kwargs)

    def save_m2m(self):
        pass

    def save(self, commit=True):
        obj = self._instance or Poll()

        obj.name = self.cleaned_data['subject']
        obj.question = 'Do you really think %(subject)s is %(adverb)s %(adjective)s?' % self.cleaned_data
        if commit:
            obj.save()

        return obj

class PollAdmin(admin.ModelAdmin):
    inlines = [PollOptionInlineAdmin]
    list_display = ('name','question', )
    fieldsets = [
        (None, {'fields': ('subject', )}),
        ('Extra', {'fields': (('adverb', 'adjective',), )}),
    ]

    def get_form(self, request, obj=None, **kwargs):
        return MyWhackyForm

admin.site.register(Poll, PollAdmin)

{'fraction_non_alphanumeric': 0.11944557684467999, 'fraction_numerical': 0.0040766408479412965, 'mean_word_length': 3.305263157894737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1509701', 'n_tokens_mistral': 764, 'n_tokens_neox': 749, 'n_words': 182}