Skip to content

Instantly share code, notes, and snippets.

@rseabrook
rseabrook / copy-database-to-local.md
Created February 21, 2023 18:39
How to copy data from production postgresql database to local database running in Docker

How to copy your production Postgresql database to your local environment running in Docker

I ran into this issue specifically in the context of a Django application deployed on Render, but these steps should work for any stack running locally in a Docker container.

Why would you want to copy your production database to your local environment?

I encountered an error in production that did not occur in my local environment. I needed to debug the issue locally, but I needed a copy of the production database to properly debug it.

How to get a copy of your production database

My application is deployed on Render, which takes daily backups automatically. The Render docs explain how the backup files are created. I was able to just download the .sql.gz file of the latest backup through the Render dashboard.

@rseabrook
rseabrook / admin.py
Created October 8, 2021 18:32
Django - create an admin list filter on a calculated value
from django.contrib import admin
from .filters import CalculatedFieldFilter
from .models import Item
@admin.register(Item)
class ItemAdmin(admin.ModelAdmin):
list_display = ('val', 'calculated_field')
list_filter = (CalculatedFieldFilter, )
@rseabrook
rseabrook / paginate-shopify-api.md
Created October 16, 2019 19:00
How to iterate over all products using the Python Shopify API wrapper

How to iterate over Shopify API results

Shopify switched their API to "cursor-based pagination" in July of 2019. This eliminated the page parameter that made it simple and obvious how to get multiple pages of results.

The Python wrapper for the Shopify API actually makes it quite difficult to page through results now. The API responds with next and previous URLs via the response headers that can be used to retrieve different pages of results, but the python wrapper actually drops these headers. There is a pull request waiting to be merged that will give access to convenient next and previous methods. In the meantime, maybe this will be useful to someone else...

Requirements

  • Shopify private app with API key and password
@rseabrook
rseabrook / display-shopify-vendor-list-with-inactive-vendors.md
Created January 9, 2019 00:57
Creating a multi-column, alphabetized vendor list in Shopify including inactive vendors

Adding inactive vendors to a multi-column, alphabetized vendor list in Shopify

This extends the multi-column, alphabetized vendor list in Shopify guide.

If all of the vendors you want to include in your vendor directory already have products assigned to them, that guide is simpler. If you want to include arbitrary vendor names that are not linked to any product in your store, this is the guide for you.

Requirements

  • Responsive, multi-column layout
  • Alphabetical order from top-to-bottom and then left-to-right.
@rseabrook
rseabrook / display-shopify-vendor-list.md
Last active September 29, 2022 07:48
Creating a multi-column, alphabetized vendor list in Shopify

Creating a multi-column, alphabetized vendor list in Shopify

This turned out to be more difficult than I expected, so I am documenting how I accomplished it here.

Requirements

  • Responsive, multi-column layout
  • Alphabetical order from top-to-bottom and then left-to-right.
  • Columns should be the same length. If the vendors cannot be split evenly across columns, the extra items should be spread across the left-most columns.
  • Links should point to a collection for the vendor if one exists, otherwise point to a Shopify built-in vendor page