django-import-file


Namedjango-import-file JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryDjango Mixin allows easy import of files into Django models.
upload_time2024-08-26 21:53:37
maintainerNone
docs_urlNone
authorJakub Jadczak
requires_pythonNone
licenseNone
keywords python django import file import file import excel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# django-import-file



Not ready for use yet!



Developed by Jakub Jadczak, 2024



## Examples of How To Use with Django Class Based View



Simple Usage



Read csv



```python



from django_import_file import FileImportMixin



class ImportFile(FileImportMixin, FormView):

    model = RowsData

    form_class = ImportFileForm

    template_name = "main/home.html"

    file_extension = "csv"

    file_encoding = "utf-8"

    delimiter = ";"

    required_columns = ["name", "age", "email", "phone", "address"]

    messages_success = "Import successful with no errors."

    success_url = reverse_lazy("main:home")

```



Read xlsx



```python

class ImportFile(FileImportMixin, FormView):

    model = RowsData

    template_name = "main/home.html"

    file_extension = "xlsx"

    required_columns = ["name", "age", "email", "phone", "address"]

    sheet_name = "Sheet1"

    messages_success = "Import successful with no errors."

    form_class = ImportFileForm

    success_url = reverse_lazy("main:home")

```



With additional calculation method



```python

class ImportFile(FileImportMixin, FormView):

    model = RowsData

    form_class = ImportFileForm

    template_name = "main/home.html"

    file_extension = "csv"

    file_encoding = "utf-8"

    delimiter = ";"

    required_columns = ["name", "age", "email", "phone", "address"]

    messages_success = "Import successful with no errors."

    success_url = reverse_lazy("main:home")



    def calculate_district(self, row):

        # name after _ must be equal to field in model, you want to calculate

        if ...:

            return "..."

        else:

            return "..."



    def get_file_content(self, file_path: str):

        df =  super().get_file_content(file_path)

        df["age"] = df["age"] + 10

        return df

```



Options:



```python

#import

from django_import_file import FileImportMixin



#Declarations, examples

file_extension = "csv"

use_verbose = True # map column using verbose_name (columns name in the file must be equal to verbose_names)

map_column = {"name": "Full Name"} # map your own columns name, {model_name: file_name}

sheet_name = "Sheet1" # used in xlsx

required_columns = ["age", "name"] 

exclude_columns = ["address"]

delimiter = ";"

file_encoding = "utf-16-le"



```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-import-file",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, django, import, file, import file, import excel",
    "author": "Jakub Jadczak",
    "author_email": "<jakubjadczak02@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/22/65/2675baa7edd8bdac563f843b36622e6d11e6a3ea0cb5fcfb58251899edca/django_import_file-0.0.6.tar.gz",
    "platform": null,
    "description": "\r\n# django-import-file\r\n\r\n\r\n\r\nNot ready for use yet!\r\n\r\n\r\n\r\nDeveloped by Jakub Jadczak, 2024\r\n\r\n\r\n\r\n## Examples of How To Use with Django Class Based View\r\n\r\n\r\n\r\nSimple Usage\r\n\r\n\r\n\r\nRead csv\r\n\r\n\r\n\r\n```python\r\n\r\n\r\n\r\nfrom django_import_file import FileImportMixin\r\n\r\n\r\n\r\nclass ImportFile(FileImportMixin, FormView):\r\n\r\n    model = RowsData\r\n\r\n    form_class = ImportFileForm\r\n\r\n    template_name = \"main/home.html\"\r\n\r\n    file_extension = \"csv\"\r\n\r\n    file_encoding = \"utf-8\"\r\n\r\n    delimiter = \";\"\r\n\r\n    required_columns = [\"name\", \"age\", \"email\", \"phone\", \"address\"]\r\n\r\n    messages_success = \"Import successful with no errors.\"\r\n\r\n    success_url = reverse_lazy(\"main:home\")\r\n\r\n```\r\n\r\n\r\n\r\nRead xlsx\r\n\r\n\r\n\r\n```python\r\n\r\nclass ImportFile(FileImportMixin, FormView):\r\n\r\n    model = RowsData\r\n\r\n    template_name = \"main/home.html\"\r\n\r\n    file_extension = \"xlsx\"\r\n\r\n    required_columns = [\"name\", \"age\", \"email\", \"phone\", \"address\"]\r\n\r\n    sheet_name = \"Sheet1\"\r\n\r\n    messages_success = \"Import successful with no errors.\"\r\n\r\n    form_class = ImportFileForm\r\n\r\n    success_url = reverse_lazy(\"main:home\")\r\n\r\n```\r\n\r\n\r\n\r\nWith additional calculation method\r\n\r\n\r\n\r\n```python\r\n\r\nclass ImportFile(FileImportMixin, FormView):\r\n\r\n    model = RowsData\r\n\r\n    form_class = ImportFileForm\r\n\r\n    template_name = \"main/home.html\"\r\n\r\n    file_extension = \"csv\"\r\n\r\n    file_encoding = \"utf-8\"\r\n\r\n    delimiter = \";\"\r\n\r\n    required_columns = [\"name\", \"age\", \"email\", \"phone\", \"address\"]\r\n\r\n    messages_success = \"Import successful with no errors.\"\r\n\r\n    success_url = reverse_lazy(\"main:home\")\r\n\r\n\r\n\r\n    def calculate_district(self, row):\r\n\r\n        # name after _ must be equal to field in model, you want to calculate\r\n\r\n        if ...:\r\n\r\n            return \"...\"\r\n\r\n        else:\r\n\r\n            return \"...\"\r\n\r\n\r\n\r\n    def get_file_content(self, file_path: str):\r\n\r\n        df =  super().get_file_content(file_path)\r\n\r\n        df[\"age\"] = df[\"age\"] + 10\r\n\r\n        return df\r\n\r\n```\r\n\r\n\r\n\r\nOptions:\r\n\r\n\r\n\r\n```python\r\n\r\n#import\r\n\r\nfrom django_import_file import FileImportMixin\r\n\r\n\r\n\r\n#Declarations, examples\r\n\r\nfile_extension = \"csv\"\r\n\r\nuse_verbose = True # map column using verbose_name (columns name in the file must be equal to verbose_names)\r\n\r\nmap_column = {\"name\": \"Full Name\"} # map your own columns name, {model_name: file_name}\r\n\r\nsheet_name = \"Sheet1\" # used in xlsx\r\n\r\nrequired_columns = [\"age\", \"name\"] \r\n\r\nexclude_columns = [\"address\"]\r\n\r\ndelimiter = \";\"\r\n\r\nfile_encoding = \"utf-16-le\"\r\n\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Django Mixin allows easy import of files into Django models.",
    "version": "0.0.6",
    "project_urls": null,
    "split_keywords": [
        "python",
        " django",
        " import",
        " file",
        " import file",
        " import excel"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af3fecce6d8ce599e78bc2f3a1a7f0e07aa4f847576ce3807a7d721170f8bad2",
                "md5": "01b841a9e2691afd936ea29bd4faa363",
                "sha256": "13b6b076b154b2afccda318ca415e190e80fe7cb506b2ff00d1a303a250d08ba"
            },
            "downloads": -1,
            "filename": "django_import_file-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "01b841a9e2691afd936ea29bd4faa363",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5760,
            "upload_time": "2024-08-26T21:53:35",
            "upload_time_iso_8601": "2024-08-26T21:53:35.805995Z",
            "url": "https://files.pythonhosted.org/packages/af/3f/ecce6d8ce599e78bc2f3a1a7f0e07aa4f847576ce3807a7d721170f8bad2/django_import_file-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22652675baa7edd8bdac563f843b36622e6d11e6a3ea0cb5fcfb58251899edca",
                "md5": "830121d6cc52b8a393297889c6967a8d",
                "sha256": "27484451ca7d85bde821f198bf9e705487cee560be402eed8f0c918c0fe0c42a"
            },
            "downloads": -1,
            "filename": "django_import_file-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "830121d6cc52b8a393297889c6967a8d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5663,
            "upload_time": "2024-08-26T21:53:37",
            "upload_time_iso_8601": "2024-08-26T21:53:37.245876Z",
            "url": "https://files.pythonhosted.org/packages/22/65/2675baa7edd8bdac563f843b36622e6d11e6a3ea0cb5fcfb58251899edca/django_import_file-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 21:53:37",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "django-import-file"
}
        
Elapsed time: 1.05375s