from django.db import models


class Variable(models.Model):
    """ An IPEDS report variable """
    code = models.CharField(max_length=20)
    short_name = models.CharField(max_length=8)
    category = models.CharField(max_length=150)
    long_name = models.CharField(max_length=80)
    raw = models.CharField(max_length=800, unique=True)


from django.contrib import admin


class VariableAdmin(admin.ModelAdmin):
    list_display = ('long_name', 'code', 'short_name', 'category')
    list_filter = ('code', 'short_name')
    list_per_page = 250  # limit of 250 variables per report
    search_fields = ('category', 'long_name')

    def make_MVL(self, request, queryset):
        from django.http import HttpResponse
        from datetime import datetime
        response = HttpResponse("".join(queryset.values_list('raw', flat=True)),
            mimetype="text/plain")
        filename = datetime.now().isoformat().split('.')[0].replace(':', '-')
        filename += "-q%s" % queryset.count()
        response['Content-Disposition'] = 'attachment; filename=ipeds-%s.mvl' % filename
        return response
    actions = ['make_MVL']

admin.site.register(Variable, VariableAdmin)

@@ -1,20 +1,53 @@
+from django.contrib import admin%0A
 from django.db impor
@@ -55,16 +55,16 @@
  models%0A
-
 %0A%0Aclass 
@@ -371,42 +371,53 @@
 ue)%0A
-%0A%0Afrom django.contrib import admin
+    used = models.BooleanField(default=False)
 %0A%0A%0Ac
@@ -560,16 +560,24 @@
 rt_name'
+, 'used'
 )%0A    li
@@ -1161,32 +1161,223 @@
 nse%0A
-    actions = %5B'make_MVL
+%0A    def mark_used(self, request, queryset):%0A        queryset.update(used=True)%0A%0A    def mark_unused(self, request, queryset):%0A        queryset.update(used=False)%0A    actions = %5B'make_MVL', 'mark_used', 'mark_unused
 '%5D%0A%0A

add boolean on ipeds importer variables as a flag for if it's been used already