<commit_before>"""Models used by the static media management application."""

from django.db import models


class Label(models.Model):
    
    """
    A notional label used to organise static media.
    
    This does not correspond to a physical label on the disk.
    """
    
    name = models.CharField(max_length=200)
    
    def __unicode__(self):
        """Returns the name of the label."""
        return self.name
    
    class Meta:
        ordering = ("name",)
    
    
class File(models.Model):
    
    """A static file."""
    
    title = models.CharField(max_length=200,
                             help_text="The title will be used as the default rollover text when this media is embedded in a web page.")
    
    labels = models.ManyToManyField(
        Label,
        blank = True,
        help_text = "Labels are used to help organise your media. They are not visible to users on your website.",
    )
    
    file = models.FileField(
        upload_to = "uploads/files",
        max_length = 250,
    )
    
    def get_absolute_url(self):
        """Generates the absolute URL of the image."""
        return self.file.url
    
    def __unicode__(self):
        """Returns the title of the media."""
        return self.title
    
    class Meta:
        ordering = ("title",)


class FileRefField(models.ForeignKey):
    
    """A foreign key to a File, constrained to only select image files."""
    
    def __init__(self, **kwargs):
        kwargs["to"] = File
        kwargs.setdefault("related_name", "+")
        kwargs.setdefault("on_delete", models.PROTECT)
        super(FileRefField, self).__init__(**kwargs)


IMAGE_FILTER = {"file__iregex": ur"\.(png|gif|jpg|jpeg)$"} 
        
class ImageRefField(FileRefField):
    
    """A foreign key to a File, constrained to only select image files."""
    
    def __init__(self, **kwargs):<commit_msg>Making default widget for FileRefField and ImageRefField be the admin raw id widget.<commit_after>"""Models used by the static media management application."""

from django.db import models
from django.contrib import admin
from django.contrib.admin.widgets import ForeignKeyRawIdWidget


class Label(models.Model):
    
    """
    A notional label used to organise static media.
    
    This does not correspond to a physical label on the disk.
    """
    
    name = models.CharField(max_length=200)
    
    def __unicode__(self):
        """Returns the name of the label."""
        return self.name
    
    class Meta:
        ordering = ("name",)
    
    
class File(models.Model):
    
    """A static file."""
    
    title = models.CharField(max_length=200,
                             help_text="The title will be used as the default rollover text when this media is embedded in a web page.")
    
    labels = models.ManyToManyField(
        Label,
        blank = True,
        help_text = "Labels are used to help organise your media. They are not visible to users on your website.",
    )
    
    file = models.FileField(
        upload_to = "uploads/files",
        max_length = 250,
    )
    
    def get_absolute_url(self):
        """Generates the absolute URL of the image."""
        return self.file.url
    
    def __unicode__(self):
        """Returns the title of the media."""
        return self.title
    
    class Meta:
        ordering = ("title",)


class FileRefField(models.ForeignKey):
    
    """A foreign key to a File, constrained to only select image files."""
    
    def __init__(self, **kwargs):
        kwargs["to"] = File
        kwargs.setdefault("related_name", "+")
        kwargs.setdefault("on_delete", models.PROTECT)
        super(FileRefField, self).__init__(**kwargs)
        
    def formfield(self, **kwargs):
        defaults = {
            "widget": ForeignKeyRawIdWidget(self.rel, admin.site), 
        }
        return super(FileRefField, self).formfield(**defaults)


IMAGE_FILTER = {"file__iregex": ur"\.(png|gif|jpg|jpeg)$"} 
        
class ImageRefField(FileRefField):
    
    """A foreign key to a File, constrained to only select image files."""
    
    def __init__(self, **kwargs):
{'fraction_non_alphanumeric': 0.10436249698722584, 'fraction_numerical': 0.004338394793926247, 'mean_word_length': 2.3576051779935274, 'pattern_counts': {'":': 3, '<': 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': '2985881', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1136, 'n_words': 375}