{"id":13448813,"url":"https://github.com/django-macaddress/django-macaddress","last_synced_at":"2026-01-12T02:37:33.565Z","repository":{"id":2039021,"uuid":"2975970","full_name":"django-macaddress/django-macaddress","owner":"django-macaddress","description":"MAC address Model Field \u0026 Form Field for Django apps","archived":false,"fork":false,"pushed_at":"2021-05-13T23:58:20.000Z","size":70,"stargazers_count":52,"open_issues_count":5,"forks_count":26,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-05-16T14:42:55.108Z","etag":null,"topics":["django","macaddress","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/django-macaddress.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-12-13T22:36:52.000Z","updated_at":"2024-04-24T22:08:17.000Z","dependencies_parsed_at":"2022-09-19T14:41:23.046Z","dependency_job_id":null,"html_url":"https://github.com/django-macaddress/django-macaddress","commit_stats":null,"previous_names":["tubaman/django-macaddress"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-macaddress%2Fdjango-macaddress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-macaddress%2Fdjango-macaddress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-macaddress%2Fdjango-macaddress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-macaddress%2Fdjango-macaddress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/django-macaddress","download_url":"https://codeload.github.com/django-macaddress/django-macaddress/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245002819,"owners_count":20545499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","macaddress","python","python3"],"created_at":"2024-07-31T06:00:21.728Z","updated_at":"2026-01-12T02:37:33.540Z","avatar_url":"https://github.com/django-macaddress.png","language":"Python","funding_links":[],"categories":["Fields","数据项"],"sub_categories":[],"readme":"django-macaddress\n==================\n\n.. image:: https://travis-ci.org/django-macaddress/django-macaddress.svg?branch=master\n   :alt: Build Status\n   :target: https://travis-ci.org/django-macaddress/django-macaddress\n.. image:: https://img.shields.io/pypi/v/django-macaddress.svg\n   :target: https://crate.io/packages/django-macaddress\n\nMAC Address model and form fields for Django\n\nWe use netaddr to parse and validate the MAC address.  The tests aren't\ncomplete yet.\n\nPatches welcome: http://github.com/django-macaddress/django-macaddress\n\nRelease Notes:\n**************\n\nFor release info: https://github.com/django-macaddress/django-macaddress/releases\n\n\nGetting Started\n***************\n\nsettings.MACADDRESS_DEFAULT_DIALECT\n-----------------------------------\nTo specify a default dialect for presentation (and storage, see below), specify::\n    \n    settings.MACADDRESS_DEFAULT_DIALECT = 'module.dialect_class'\n\nwhere the specified value is a string composed of a parent python module name \nand the child dialect class name. For example::\n\n    settings.MACADDRESS_DEFAULT_DIALECT = 'netaddr.mac_eui48'\n\nPS: old default of macaddress.mac_linux (uppercase and divided by ':' ) will be used by default.\n\nIf the custom dialect is defined in a package module, you will need to define the \nclass in or import into the package's ``__init__.py``.\n\n``default_dialect`` and ``format_mac``\n--------------------------------------\nTo get the default dialect for your project, import and call the ``default_dialect`` function::\n\n    \u003e\u003e\u003e from macaddress import default_dialect\n    \n    \u003e\u003e\u003e dialect = default_dialect()\n    \nThis function may, optionally, be called with an ``netaddr.EUI`` class instance as its argument. If no\ndefault is defined in ``settings``, it will return the dialect of the provided ``EUI`` object.\n\nThe ``format_mac`` function takes an ``EUI`` instance and a dialect class (``netaddr.mac_eui48`` or a \nsubclass) as its arguments. The dialect class may be specified as a string in the same manner as \n``settings.MACADDRESS_DEFAULT_DIALECT``::\n    \n    \u003e\u003e\u003e from netaddr import EUI, mac_bare\n    \u003e\u003e\u003e from macaddress import format_mac\n\n    \u003e\u003e\u003e mac = EUI('00:12:3c:37:64:8f')\n    \u003e\u003e\u003e format_mac(mac, mac_bare)\n    '00123C37648F'\n    \u003e\u003e\u003e format_mac(mac, 'netaddr.mac_cisco')\n    '0012.3c37.648f'\n    \nMACAddressField (ModelField)\n----------------------------\nThis is an example model using MACAddressField::\n    \n    from macaddress.fields import MACAddressField\n    \n    class Computer(models.Model):\n        name = models.CharField(max_length=32)\n        eth0 = MACAddressField(null=True, blank=True)\n        ...\n    \nThe default behavior is to store the MAC Address in the database is a BigInteger. \nIf you would, rather, store the value as a string (to, for instance, facilitate \nsub-string searches), you can specify ``integer=False`` and the value will be stored\nas a string::\n\n    class Computer(models.Model):\n        name = models.CharField(max_length=32)\n        eth0 = MACAddressField(blank=True, integer=False)\n        ...\n\nIf you want to set ``unique=True`` on a MACAddressField that is stored as a string, you will need \nto set ``null=True`` and create custom ``clean_\u003cfoo\u003e`` methods on your ``forms.ModelForm`` class for \neach MACAddressField that return ``None`` when the value provided is an ``''`` (empty string)::\n\n    from .models import Computer\n    \n    class ComputerForm(forms.ModelForm):\n        class Meta:\n            model = Computer\n        \n        def clean_eth0(self):\n            return self.cleaned_data['eth0'] or None\n        \nYou should avoid changing the value of ``integer`` after running ``managy.py syncdb``, \nunless you are using a schema migration solution like South or Django's built-in migrations.\n\n\nTo Do\n*****\n\n+ Add greater support for partial string queries when storing MACs as strings in the database.\n+ Add custom validator to check for duplicate MACs when mixing string and integer storage types.\n+ Add deprecation warning and timeline for changeover to default string storage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjango-macaddress%2Fdjango-macaddress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjango-macaddress%2Fdjango-macaddress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjango-macaddress%2Fdjango-macaddress/lists"}